From f76f5db2fae2eb1216b852574a18bb84b789dadd Mon Sep 17 00:00:00 2001 From: Sebastian Sumpf Date: Fri, 11 Nov 2022 10:14:08 +0100 Subject: [PATCH] drivers: use DMA buffer more consistent Replace 'alloc_dma_buffer' by 'Dma_buffer' issue #4667 --- repos/os/src/drivers/framebuffer/pl11x/main.cc | 12 ++++-------- repos/os/src/drivers/framebuffer/ram/main.cc | 18 +++++++----------- repos/os/src/test/platform_drv/main.cc | 11 ++++++----- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/repos/os/src/drivers/framebuffer/pl11x/main.cc b/repos/os/src/drivers/framebuffer/pl11x/main.cc index fd33426c0f..4f0b2e5a06 100644 --- a/repos/os/src/drivers/framebuffer/pl11x/main.cc +++ b/repos/os/src/drivers/framebuffer/pl11x/main.cc @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -73,7 +74,7 @@ struct Pl11x_driver::Main { using Pixel = Capture::Pixel; - Surface surface(_fb_ds.local_addr(), _size); + Surface surface(_fb_dma.local_addr(), _size); _captured_screen.apply_to_surface(surface); } @@ -90,11 +91,7 @@ struct Pl11x_driver::Main Platform::Device _sp810_dev { _platform, Type { "arm,sp810" } }; Platform::Device::Mmio _lcd_io_mem { _pl11x_dev }; Platform::Device::Mmio _sys_mem { _sp810_dev }; - - Ram_dataspace_capability _fb_ds_cap { - _platform.alloc_dma_buffer(FRAMEBUFFER_SIZE, UNCACHED) }; - - Attached_dataspace _fb_ds { _env.rm(), _fb_ds_cap }; + Platform::Dma_buffer _fb_dma { _platform, FRAMEBUFFER_SIZE, UNCACHED }; void _init_device(); @@ -197,8 +194,7 @@ void Pl11x_driver::Main::_init_device() reg_write(PL11X_REG_TIMING3, tim3); /* set framebuffer address and ctrl register */ - addr_t const fb_dma_base = (addr_t)_platform.dma_addr(_fb_ds_cap); - reg_write(PL11X_REG_UPBASE, fb_dma_base); + reg_write(PL11X_REG_UPBASE, _fb_dma.dma_addr()); reg_write(PL11X_REG_LPBASE, 0); reg_write(PL11X_REG_IMSC, 0); reg_write(PL11X_REG_CTRL, ctrl); diff --git a/repos/os/src/drivers/framebuffer/ram/main.cc b/repos/os/src/drivers/framebuffer/ram/main.cc index 208d095435..f0db5be48e 100644 --- a/repos/os/src/drivers/framebuffer/ram/main.cc +++ b/repos/os/src/drivers/framebuffer/ram/main.cc @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -61,13 +62,8 @@ class Main Platform::Device::Mmio _fw_mem { _fw_dev }; Fw _fw { (addr_t)_fw_mem.local_addr() }; - Ram_dataspace_capability _fb_ds_cap { - _platform.alloc_dma_buffer(SCR_HEIGHT * SCR_STRIDE, UNCACHED) }; - Attached_dataspace _fb_ds { _env.rm(), _fb_ds_cap }; - - Ram_dataspace_capability _config_ds_cap { - _platform.alloc_dma_buffer(0x1000, UNCACHED) }; - Attached_dataspace _config_ds { _env.rm(), _config_ds_cap }; + Platform::Dma_buffer _fb_dma { _platform, SCR_HEIGHT * SCR_STRIDE, UNCACHED }; + Platform::Dma_buffer _config_dma { _platform, 0x1000, UNCACHED }; Capture::Area const _size { SCR_WIDTH, SCR_HEIGHT }; Capture::Connection _capture { _env }; @@ -81,7 +77,7 @@ class Main { using Pixel = Capture::Pixel; - Surface surface(_fb_ds.local_addr(), _size); + Surface surface(_fb_dma.local_addr(), _size); _captured_screen.apply_to_surface(surface); } @@ -173,9 +169,9 @@ class Main _fw_selector(file.key); - addr_t config_addr = (addr_t)_config_ds.local_addr(); - addr_t config_phys = (addr_t)_platform.dma_addr(_config_ds_cap); - addr_t fb_phys = (addr_t)_platform.dma_addr(_fb_ds_cap); + addr_t config_addr = (addr_t)_config_dma.local_addr(); + addr_t config_phys = _config_dma.dma_addr(); + addr_t fb_phys = _fb_dma.dma_addr(); Ram_fb_config config { config_addr }; config.write(host_to_big_endian(fb_phys)); diff --git a/repos/os/src/test/platform_drv/main.cc b/repos/os/src/test/platform_drv/main.cc index f4ce9192fc..f859c9ed4b 100644 --- a/repos/os/src/test/platform_drv/main.cc +++ b/repos/os/src/test/platform_drv/main.cc @@ -14,7 +14,6 @@ #include #include #include - /* WARNING DO NOT COPY THIS !!! */ /* * We make everything public from the platform device classes @@ -25,6 +24,8 @@ #undef private /* WARNING DO NOT COPY THIS !!! */ +#include + using namespace Genode; struct Main @@ -158,7 +159,7 @@ struct Main case 3: next_step(4, 4, 0x40000000, 32); return; - case 4: + case 4: { /* Instantiate and destroy all devices */ start_driver(0); start_driver(1); @@ -169,7 +170,7 @@ struct Main stop_driver(2); stop_driver(3); /* allocate big DMA dataspace */ - platform->alloc_dma_buffer(0x80000, UNCACHED); + Platform::Dma_buffer buffer { *platform, 0x80000, UNCACHED }; /* close the whole session */ platform.destruct(); platform.construct(env); @@ -180,10 +181,10 @@ struct Main start_driver(3); /* repeatedly start and destroy device sessions to detect leakages */ for (unsigned idx = 0; idx < 1000; idx++) { - platform->free_dma_buffer(platform->alloc_dma_buffer(0x4000, UNCACHED)); + Platform::Dma_buffer dma { *platform, 0x4000, UNCACHED }; } next_step(0, 0, 0x40000000, 32); - return; + return; } case 5: stop_driver(0); stop_driver(1);