^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Exercise /dev/mem mmap cases that have been troublesome in the past
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * (c) Copyright 2007 Hewlett-Packard Development Company, L.P.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Bjorn Helgaas <bjorn.helgaas@hp.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <stdlib.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <stdio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <sys/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <dirent.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <fcntl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <fnmatch.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <sys/ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <sys/mman.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <sys/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <unistd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) int sum;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static int map_mem(char *path, off_t offset, size_t length, int touch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) int fd, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) void *addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) int *c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) fd = open(path, O_RDWR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) if (fd == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) perror(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) if (fnmatch("/proc/bus/pci/*", path, 0) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) rc = ioctl(fd, PCIIOC_MMAP_IS_MEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) if (rc == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) perror("PCIIOC_MMAP_IS_MEM ioctl");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) addr = mmap(NULL, length, PROT_READ|PROT_WRITE, MAP_SHARED, fd, offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) if (addr == MAP_FAILED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) if (touch) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) c = (int *) addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) while (c < (int *) (addr + length))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) sum += *c++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) rc = munmap(addr, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) if (rc == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) perror("munmap");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) close(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static int scan_tree(char *path, char *file, off_t offset, size_t length, int touch)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct dirent **namelist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) char *name, *path2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) int i, n, r, rc = 0, result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct stat buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) n = scandir(path, &namelist, 0, alphasort);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (n < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) perror("scandir");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) for (i = 0; i < n; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) name = namelist[i]->d_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (fnmatch(".", name, 0) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) goto skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) if (fnmatch("..", name, 0) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) goto skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) path2 = malloc(strlen(path) + strlen(name) + 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) strcpy(path2, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) strcat(path2, "/");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) strcat(path2, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (fnmatch(file, name, 0) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) rc = map_mem(path2, offset, length, touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if (rc == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) fprintf(stderr, "PASS: %s 0x%lx-0x%lx is %s\n", path2, offset, offset + length, touch ? "readable" : "mappable");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) else if (rc > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) fprintf(stderr, "PASS: %s 0x%lx-0x%lx not mappable\n", path2, offset, offset + length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) fprintf(stderr, "FAIL: %s 0x%lx-0x%lx not accessible\n", path2, offset, offset + length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) r = lstat(path2, &buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) if (r == 0 && S_ISDIR(buf.st_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) rc = scan_tree(path2, file, offset, length, touch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) result |= rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) free(path2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) skip:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) free(namelist[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) free(namelist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) char buf[1024];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static int read_rom(char *path)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int fd, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) size_t size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) fd = open(path, O_RDWR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) if (fd == -1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) perror(path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) rc = write(fd, "1", 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) if (rc <= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) close(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) perror("write");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) rc = read(fd, buf, sizeof(buf));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) if (rc > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) size += rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) } while (rc > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) close(fd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) return size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) static int scan_rom(char *path, char *file)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct dirent **namelist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) char *name, *path2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) int i, n, r, rc = 0, result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct stat buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) n = scandir(path, &namelist, 0, alphasort);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) if (n < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) perror("scandir");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) for (i = 0; i < n; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) name = namelist[i]->d_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) if (fnmatch(".", name, 0) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) goto skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (fnmatch("..", name, 0) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) goto skip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) path2 = malloc(strlen(path) + strlen(name) + 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) strcpy(path2, path);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) strcat(path2, "/");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) strcat(path2, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (fnmatch(file, name, 0) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) rc = read_rom(path2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * It's OK if the ROM is unreadable. Maybe there
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * is no ROM, or some other error occurred. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) * important thing is that no MCA happened.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (rc > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) fprintf(stderr, "PASS: %s read %d bytes\n", path2, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) fprintf(stderr, "PASS: %s not readable\n", path2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) r = lstat(path2, &buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (r == 0 && S_ISDIR(buf.st_mode)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) rc = scan_rom(path2, file);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) result |= rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) free(path2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) skip:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) free(namelist[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) free(namelist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) int main(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (map_mem("/dev/mem", 0, 0xA0000, 1) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) fprintf(stderr, "PASS: /dev/mem 0x0-0xa0000 is readable\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) fprintf(stderr, "FAIL: /dev/mem 0x0-0xa0000 not accessible\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * It's not safe to blindly read the VGA frame buffer. If you know
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * how to poke the card the right way, it should respond, but it's
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * not safe in general. Many machines, e.g., Intel chipsets, cover
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * up a non-responding card by just returning -1, but others will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * report the failure as a machine check.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) if (map_mem("/dev/mem", 0xA0000, 0x20000, 0) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) fprintf(stderr, "PASS: /dev/mem 0xa0000-0xc0000 is mappable\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) fprintf(stderr, "FAIL: /dev/mem 0xa0000-0xc0000 not accessible\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (map_mem("/dev/mem", 0xC0000, 0x40000, 1) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) fprintf(stderr, "PASS: /dev/mem 0xc0000-0x100000 is readable\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) fprintf(stderr, "FAIL: /dev/mem 0xc0000-0x100000 not accessible\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * Often you can map all the individual pieces above (0-0xA0000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) * 0xA0000-0xC0000, and 0xC0000-0x100000), but can't map the whole
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) * thing at once. This is because the individual pieces use different
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) * attributes, and there's no single attribute supported over the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) * whole region.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) rc = map_mem("/dev/mem", 0, 1024*1024, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (rc == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) fprintf(stderr, "PASS: /dev/mem 0x0-0x100000 is mappable\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) else if (rc > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) fprintf(stderr, "PASS: /dev/mem 0x0-0x100000 not mappable\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) fprintf(stderr, "FAIL: /dev/mem 0x0-0x100000 not accessible\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) scan_tree("/sys/class/pci_bus", "legacy_mem", 0, 0xA0000, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) scan_tree("/sys/class/pci_bus", "legacy_mem", 0xA0000, 0x20000, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) scan_tree("/sys/class/pci_bus", "legacy_mem", 0xC0000, 0x40000, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) scan_tree("/sys/class/pci_bus", "legacy_mem", 0, 1024*1024, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) scan_rom("/sys/devices", "rom");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) scan_tree("/proc/bus/pci", "??.?", 0, 0xA0000, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) scan_tree("/proc/bus/pci", "??.?", 0xA0000, 0x20000, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) scan_tree("/proc/bus/pci", "??.?", 0xC0000, 0x40000, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) scan_tree("/proc/bus/pci", "??.?", 0, 1024*1024, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }