This source file includes following definitions.
- acpi_os_get_page_size
- acpi_os_map_memory
- acpi_os_unmap_memory
1
2
3
4
5
6
7
8
9
10 #include "acpidump.h"
11 #include <unistd.h>
12 #include <sys/mman.h>
13 #ifdef _free_BSD
14 #include <sys/param.h>
15 #endif
16
17 #define _COMPONENT ACPI_OS_SERVICES
18 ACPI_MODULE_NAME("osunixmap")
19
20 #ifndef O_BINARY
21 #define O_BINARY 0
22 #endif
23 #if defined(_dragon_fly) || defined(_free_BSD) || defined(_QNX)
24 #define MMAP_FLAGS MAP_SHARED
25 #else
26 #define MMAP_FLAGS MAP_PRIVATE
27 #endif
28 #define SYSTEM_MEMORY "/dev/mem"
29
30
31
32
33
34
35
36
37
38
39
40 static acpi_size acpi_os_get_page_size(void)
41 {
42
43 #ifdef PAGE_SIZE
44 return PAGE_SIZE;
45 #else
46 return sysconf(_SC_PAGESIZE);
47 #endif
48 }
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 void *acpi_os_map_memory(acpi_physical_address where, acpi_size length)
64 {
65 u8 *mapped_memory;
66 acpi_physical_address offset;
67 acpi_size page_size;
68 int fd;
69
70 fd = open(SYSTEM_MEMORY, O_RDONLY | O_BINARY);
71 if (fd < 0) {
72 fprintf(stderr, "Cannot open %s\n", SYSTEM_MEMORY);
73 return (NULL);
74 }
75
76
77
78 page_size = acpi_os_get_page_size();
79 offset = where % page_size;
80
81
82
83 mapped_memory = mmap(NULL, (length + offset), PROT_READ, MMAP_FLAGS,
84 fd, (where - offset));
85 if (mapped_memory == MAP_FAILED) {
86 fprintf(stderr, "Cannot map %s\n", SYSTEM_MEMORY);
87 close(fd);
88 return (NULL);
89 }
90
91 close(fd);
92 return (ACPI_CAST8(mapped_memory + offset));
93 }
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109 void acpi_os_unmap_memory(void *where, acpi_size length)
110 {
111 acpi_physical_address offset;
112 acpi_size page_size;
113
114 page_size = acpi_os_get_page_size();
115 offset = ACPI_TO_INTEGER(where) % page_size;
116 munmap((u8 *)where - offset, (length + offset));
117 }