diff options
author | Damien Zammit <damien@zamaudio.com> | 2022-09-12 10:40:08 +0000 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2022-09-12 20:39:00 +0200 |
commit | 432ecc4bed0ef5341d8dc7637d7631fe05ffd717 (patch) | |
tree | fb492ddd8a1e743baad2954c517e6fd853a9d52b /acpi | |
parent | 4830c981325d53f8a4372288dbf0ef77a22059da (diff) | |
download | hurd-432ecc4bed0ef5341d8dc7637d7631fe05ffd717.tar.gz hurd-432ecc4bed0ef5341d8dc7637d7631fe05ffd717.tar.bz2 hurd-432ecc4bed0ef5341d8dc7637d7631fe05ffd717.zip |
acpi: Remove references to /dev/mem
Message-Id: <20220912103837.556815-5-damien@zamaudio.com>
Diffstat (limited to 'acpi')
-rw-r--r-- | acpi/acpi.c | 109 |
1 files changed, 34 insertions, 75 deletions
diff --git a/acpi/acpi.c b/acpi/acpi.c index 9827232a..dd32d60f 100644 --- a/acpi/acpi.c +++ b/acpi/acpi.c @@ -30,37 +30,13 @@ #include "myacpi.h" -int -mmap_phys_acpi_header(uintptr_t base_addr, struct acpi_header **ptr_to_header, - void **virt_addr, int fd) -{ - /* The memory mapping must be done aligned to page size - * but we have a known physical address we want to inspect, - * therefore we must compute offsets. - */ - uintptr_t pa_acpi = base_addr & ~(sysconf(_SC_PAGE_SIZE) - 1); - uintptr_t pa_start = base_addr - pa_acpi; - - /* Map the ACPI table at the nearest page (rounded down) */ - *virt_addr = 0; - *virt_addr = mmap(NULL, ESCD_SIZE, PROT_READ, MAP_SHARED, - fd, (off_t) pa_acpi); - - if (*virt_addr == MAP_FAILED) - return errno; - - /* Fabricate a pointer to our magic address */ - *ptr_to_header = (struct acpi_header *)(*virt_addr + pa_start); - - return 0; -} +#define __KERNEL__ +#include <acpi/acpi.h> int acpi_get_num_tables(size_t *num_tables) { - int fd_mem; - int err; - void *virt_addr, *virt_addr2; + void *virt_addr; bool found = false; struct rsdp_descr2 rsdp = { 0 }; uintptr_t sdt_base = (uintptr_t)0; @@ -69,11 +45,7 @@ acpi_get_num_tables(size_t *num_tables) struct acpi_header *root_sdt; struct acpi_header *next; - if ((fd_mem = open("/dev/mem", O_RDWR)) < 0) - return EPERM; - - virt_addr = mmap(NULL, ESCD_SIZE, PROT_READ, - MAP_SHARED, fd_mem, ESCD); + virt_addr = acpi_os_map_memory(ESCD, ESCD_SIZE); if (virt_addr == MAP_FAILED) return errno; @@ -91,7 +63,7 @@ acpi_get_num_tables(size_t *num_tables) } if (!found) { - munmap(virt_addr, ESCD_SIZE); + acpi_os_unmap_memory(virt_addr, ESCD_SIZE); return ENODEV; } @@ -104,18 +76,17 @@ acpi_get_num_tables(size_t *num_tables) sdt_base = rsdp.xsdt_addr; is_64bit = true; } else { - munmap(virt_addr, ESCD_SIZE); + acpi_os_unmap_memory(virt_addr, ESCD_SIZE); return ENODEV; } - munmap(virt_addr, ESCD_SIZE); + acpi_os_unmap_memory(virt_addr, ESCD_SIZE); /* Now we have the sdt_base address and knowledge of 32/64 bit ACPI */ - err = mmap_phys_acpi_header(sdt_base, &root_sdt, &virt_addr, fd_mem); - if (err) { - return err; - } + root_sdt = acpi_os_map_memory(sdt_base, ESCD_SIZE); + if (root_sdt == MAP_FAILED) + return errno; /* Get total tables */ uint32_t ntables; @@ -133,25 +104,23 @@ acpi_get_num_tables(size_t *num_tables) uintptr_t acpi_ptr32 = (uintptr_t)*((uint32_t *)(acpi_ptr + i*sz_ptr)); uintptr_t acpi_ptr64 = (uintptr_t)*((uint64_t *)(acpi_ptr + i*sz_ptr)); if (is_64bit) { - err = mmap_phys_acpi_header(acpi_ptr64, &next, &virt_addr2, fd_mem); + next = acpi_os_map_memory(acpi_ptr64, ESCD_SIZE); } else { - err = mmap_phys_acpi_header(acpi_ptr32, &next, &virt_addr2, fd_mem); + next = acpi_os_map_memory(acpi_ptr32, ESCD_SIZE); } - if (err) { - munmap(virt_addr, ESCD_SIZE); - return err; - } + if (next == MAP_FAILED) + return errno; if (next->signature[0] == '\0' || next->length == 0) { - munmap(virt_addr2, ESCD_SIZE); + acpi_os_unmap_memory(next, ESCD_SIZE); continue; } *num_tables += 1; - munmap(virt_addr2, ESCD_SIZE); + acpi_os_unmap_memory(next, ESCD_SIZE); } - munmap(virt_addr, ESCD_SIZE); + acpi_os_unmap_memory(root_sdt, ESCD_SIZE); return 0; } @@ -160,9 +129,7 @@ int acpi_get_tables(struct acpi_table **tables) { int err; - int fd_mem; - void *virt_addr, *virt_addr2; - uint32_t phys_addr = ESCD; + void *virt_addr; bool found = false; struct rsdp_descr2 rsdp = { 0 }; uintptr_t sdt_base = (uintptr_t)0; @@ -181,12 +148,7 @@ acpi_get_tables(struct acpi_table **tables) if (!*tables) return ENOMEM; - if ((fd_mem = open("/dev/mem", O_RDWR)) < 0) - return EPERM; - - virt_addr = mmap(NULL, ESCD_SIZE, PROT_READ, MAP_SHARED, - fd_mem, (off_t) phys_addr); - + virt_addr = acpi_os_map_memory(ESCD, ESCD_SIZE); if (virt_addr == MAP_FAILED) return errno; @@ -204,7 +166,7 @@ acpi_get_tables(struct acpi_table **tables) } if (!found) { - munmap(virt_addr, ESCD_SIZE); + acpi_os_unmap_memory(virt_addr, ESCD_SIZE); return ENODEV; } @@ -217,18 +179,17 @@ acpi_get_tables(struct acpi_table **tables) sdt_base = rsdp.xsdt_addr; is_64bit = true; } else { - munmap(virt_addr, ESCD_SIZE); + acpi_os_unmap_memory(virt_addr, ESCD_SIZE); return ENODEV; } - munmap(virt_addr, ESCD_SIZE); + acpi_os_unmap_memory(virt_addr, ESCD_SIZE); /* Now we have the sdt_base address and knowledge of 32/64 bit ACPI */ - err = mmap_phys_acpi_header(sdt_base, &root_sdt, &virt_addr, fd_mem); - if (err) { - return err; - } + root_sdt = acpi_os_map_memory(sdt_base, ESCD_SIZE); + if (root_sdt == MAP_FAILED) + return errno; /* Get total tables */ uint32_t ntables; @@ -245,18 +206,16 @@ acpi_get_tables(struct acpi_table **tables) uintptr_t acpi_ptr32 = (uintptr_t)*((uint32_t *)(acpi_ptr + i*sz_ptr)); uintptr_t acpi_ptr64 = (uintptr_t)*((uint64_t *)(acpi_ptr + i*sz_ptr)); if (is_64bit) { - err = mmap_phys_acpi_header(acpi_ptr64, &next, &virt_addr2, fd_mem); + next = acpi_os_map_memory(acpi_ptr64, ESCD_SIZE); } else { - err = mmap_phys_acpi_header(acpi_ptr32, &next, &virt_addr2, fd_mem); + next = acpi_os_map_memory(acpi_ptr32, ESCD_SIZE); } - if (err) { - munmap(virt_addr, ESCD_SIZE); - return err; - } + if (next == MAP_FAILED) + return errno; if (next->signature[0] == '\0' || next->length == 0) { - munmap(virt_addr2, ESCD_SIZE); + acpi_os_unmap_memory(next, ESCD_SIZE); continue; } uint32_t datalen = next->length - sizeof(*next); @@ -270,17 +229,17 @@ acpi_get_tables(struct acpi_table **tables) t->datalen = 0; t->data = malloc(datalen); if (!t->data) { - munmap(virt_addr2, ESCD_SIZE); - munmap(virt_addr, ESCD_SIZE); + acpi_os_unmap_memory(next, ESCD_SIZE); + acpi_os_unmap_memory(root_sdt, ESCD_SIZE); return ENOMEM; } t->datalen = datalen; memcpy(t->data, data, datalen); cur_tab++; - munmap(virt_addr2, ESCD_SIZE); + acpi_os_unmap_memory(next, ESCD_SIZE); } - munmap(virt_addr, ESCD_SIZE); + acpi_os_unmap_memory(root_sdt, ESCD_SIZE); return 0; } |