acpi: Add IORT helper functions
[coreboot2.git] / util / intelmetool / mmap.c
blob988085ecd31931204337e314902a7f6e9197d749
1 /* intelmetool */
2 /* SPDX-License-Identifier: GPL-2.0-or-later */
4 #include "mmap.h"
5 #include <errno.h>
6 #include <string.h>
8 #ifndef __DARWIN__
9 int fd_mem;
11 void *map_physical_exact(off_t phys_addr, void *mapto, size_t len)
13 void *virt_addr;
14 int err;
16 virt_addr = mmap(mapto, len, PROT_WRITE | PROT_READ,
17 MAP_SHARED | MAP_FIXED, fd_mem, phys_addr);
19 if (virt_addr == MAP_FAILED) {
20 err = errno;
21 printf("Error mapping physical memory 0x%016jx [0x%zx] ERRNO=%d %s\n",
22 (uintmax_t)phys_addr, len, err, strerror(err));
23 return NULL;
26 return virt_addr;
29 void *map_physical(off_t phys_addr, size_t len)
31 void *virt_addr;
32 int err;
34 virt_addr = mmap(NULL, len, PROT_WRITE | PROT_READ, MAP_SHARED, fd_mem, phys_addr);
36 if (virt_addr == MAP_FAILED) {
37 err = errno;
38 printf("Error mapping physical memory 0x%016jx [0x%zx] ERRNO=%d %s\n",
39 (uintmax_t)phys_addr, len, err, strerror(err));
40 return NULL;
43 return virt_addr;
46 void unmap_physical(void *virt_addr, size_t len)
48 munmap(virt_addr, len);
50 #endif