diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2012-04-18 22:17:54 -0700 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2012-04-23 19:37:41 -0700 |
commit | 9f2d95e61896f41adb8087fb805eb37899cce55f (patch) | |
tree | 15cf432a3a3029a90a7141a8462512fd4f367ed9 | |
parent | d50292ca8cbbaa5e0c92627f3d7813194c7c83ac (diff) | |
download | libpciaccess-9f2d95e61896f41adb8087fb805eb37899cce55f.tar.gz libpciaccess-9f2d95e61896f41adb8087fb805eb37899cce55f.tar.bz2 libpciaccess-9f2d95e61896f41adb8087fb805eb37899cce55f.zip |
Solaris: refactor pci_device_solx_devfs_map_range to reduce code duplication
The sparc & x86 cases were doing essentially the same things with
different paths, so make the path setup be inside the platform
specific #ifdefs, make the open, mmap, & error handling common code.
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r-- | src/solx_devfs.c | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/src/solx_devfs.c b/src/solx_devfs.c index 4069dc2..3eefefb 100644 --- a/src/solx_devfs.c +++ b/src/solx_devfs.c @@ -911,7 +911,7 @@ pci_device_solx_devfs_probe( struct pci_device * dev ) } /** - * Map a memory region for a device using /dev/xsvc. + * Map a memory region for a device using /dev/xsvc (x86) or fb device (sparc) * * \param dev Device whose memory region is to be mapped. * \param map Parameters of the mapping that is to be created. @@ -927,39 +927,40 @@ pci_device_solx_devfs_map_range(struct pci_device *dev, ? (PROT_READ | PROT_WRITE) : PROT_READ; int err = 0; -#ifdef __sparc - char map_dev[128]; + const char *map_dev; int map_fd; - if (MAPPING_DEV_PATH(dev)) - snprintf(map_dev, sizeof (map_dev), "%s%s", "/devices", MAPPING_DEV_PATH(dev)); - else - strcpy (map_dev, "/dev/fb0"); +#ifdef __sparc + char map_dev_buf[128]; - if ((map_fd = open(map_dev, O_RDWR | O_CLOEXEC)) < 0) { - err = errno; - (void) fprintf(stderr, "can not open %s: %s\n", map_dev, - strerror(errno)); - return err; + if (MAPPING_DEV_PATH(dev)) { + snprintf(map_dev_buf, sizeof (map_dev_buf), "%s%s", + "/devices", MAPPING_DEV_PATH(dev)); + map_dev = map_dev_buf; } + else + map_dev = "/dev/fb0"; - map->memory = mmap(NULL, map->size, prot, MAP_SHARED, map_fd, map->base); + map_fd = -1; #else /* - * Still used xsvc to do the user space mapping + * Still uses xsvc to do the user space mapping on x86/x64, + * caches open fd across multiple calls. */ - if (xsvc_fd < 0) { - if ((xsvc_fd = open("/dev/xsvc", O_RDWR | O_CLOEXEC)) < 0) { + map_dev = "/dev/xsvc"; + map_fd = xsvc_fd; +#endif + + if (map_fd < 0) { + if ((map_fd = open(map_dev, O_RDWR | O_CLOEXEC)) < 0) { err = errno; - (void) fprintf(stderr, "can not open /dev/xsvc: %s\n", + (void) fprintf(stderr, "can not open %s: %s\n", map_dev, strerror(errno)); return err; } } - map->memory = mmap(NULL, map->size, prot, MAP_SHARED, xsvc_fd, map->base); -#endif - + map->memory = mmap(NULL, map->size, prot, MAP_SHARED, map_fd, map->base); if (map->memory == MAP_FAILED) { err = errno; |