0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include "acpidump.h"
0011 #include <unistd.h>
0012 #include <sys/mman.h>
0013 #ifdef _free_BSD
0014 #include <sys/param.h>
0015 #endif
0016
0017 #define _COMPONENT ACPI_OS_SERVICES
0018 ACPI_MODULE_NAME("osunixmap")
0019
0020 #ifndef O_BINARY
0021 #define O_BINARY 0
0022 #endif
0023 #if defined(_dragon_fly) || defined(_free_BSD) || defined(_QNX)
0024 #define MMAP_FLAGS MAP_SHARED
0025 #else
0026 #define MMAP_FLAGS MAP_PRIVATE
0027 #endif
0028 #define SYSTEM_MEMORY "/dev/mem"
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040 static acpi_size acpi_os_get_page_size(void)
0041 {
0042
0043 #ifdef PAGE_SIZE
0044 return PAGE_SIZE;
0045 #else
0046 return sysconf(_SC_PAGESIZE);
0047 #endif
0048 }
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 void *acpi_os_map_memory(acpi_physical_address where, acpi_size length)
0064 {
0065 u8 *mapped_memory;
0066 acpi_physical_address offset;
0067 acpi_size page_size;
0068 int fd;
0069
0070 fd = open(SYSTEM_MEMORY, O_RDONLY | O_BINARY);
0071 if (fd < 0) {
0072 fprintf(stderr, "Cannot open %s\n", SYSTEM_MEMORY);
0073 return (NULL);
0074 }
0075
0076
0077
0078 page_size = acpi_os_get_page_size();
0079 offset = where % page_size;
0080
0081
0082
0083 mapped_memory = mmap(NULL, (length + offset), PROT_READ, MMAP_FLAGS,
0084 fd, (where - offset));
0085 if (mapped_memory == MAP_FAILED) {
0086 fprintf(stderr, "Cannot map %s\n", SYSTEM_MEMORY);
0087 close(fd);
0088 return (NULL);
0089 }
0090
0091 close(fd);
0092 return (ACPI_CAST8(mapped_memory + offset));
0093 }
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109 void acpi_os_unmap_memory(void *where, acpi_size length)
0110 {
0111 acpi_physical_address offset;
0112 acpi_size page_size;
0113
0114 page_size = acpi_os_get_page_size();
0115 offset = ACPI_TO_INTEGER(where) % page_size;
0116 munmap((u8 *)where - offset, (length + offset));
0117 }