Nice :) Damien Zammit, le dim. 04 sept. 2022 03:47:24 +0000, a ecrit: > --- > acpi/acpi.c | 109 ++++++++++++++++------------------------------------ > 1 file 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; > } > -- > 2.34.1 > > >
-- Samuel --- Pour une évaluation indépendante, transparente et rigoureuse ! Je soutiens la Commission d'Évaluation de l'Inria.