Commit 9f2d95e6 authored by Alan Coopersmith's avatar Alan Coopersmith
Browse files

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's avatarAlan Coopersmith <alan.coopersmith@oracle.com>
parent d50292ca
...@@ -911,7 +911,7 @@ pci_device_solx_devfs_probe( struct pci_device * dev ) ...@@ -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 dev Device whose memory region is to be mapped.
* \param map Parameters of the mapping that is to be created. * \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, ...@@ -927,39 +927,40 @@ pci_device_solx_devfs_map_range(struct pci_device *dev,
? (PROT_READ | PROT_WRITE) : PROT_READ; ? (PROT_READ | PROT_WRITE) : PROT_READ;
int err = 0; int err = 0;
#ifdef __sparc const char *map_dev;
char map_dev[128];
int map_fd; int map_fd;
if (MAPPING_DEV_PATH(dev)) #ifdef __sparc
snprintf(map_dev, sizeof (map_dev), "%s%s", "/devices", MAPPING_DEV_PATH(dev)); char map_dev_buf[128];
else
strcpy (map_dev, "/dev/fb0");
if ((map_fd = open(map_dev, O_RDWR | O_CLOEXEC)) < 0) { if (MAPPING_DEV_PATH(dev)) {
err = errno; snprintf(map_dev_buf, sizeof (map_dev_buf), "%s%s",
(void) fprintf(stderr, "can not open %s: %s\n", map_dev, "/devices", MAPPING_DEV_PATH(dev));
strerror(errno)); map_dev = map_dev_buf;
return err;
} }
else
map_dev = "/dev/fb0";
map->memory = mmap(NULL, map->size, prot, MAP_SHARED, map_fd, map->base); map_fd = -1;
#else #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) { map_dev = "/dev/xsvc";
if ((xsvc_fd = open("/dev/xsvc", O_RDWR | O_CLOEXEC)) < 0) { map_fd = xsvc_fd;
#endif
if (map_fd < 0) {
if ((map_fd = open(map_dev, O_RDWR | O_CLOEXEC)) < 0) {
err = errno; 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)); strerror(errno));
return err; return err;
} }
} }
map->memory = mmap(NULL, map->size, prot, MAP_SHARED, xsvc_fd, map->base); map->memory = mmap(NULL, map->size, prot, MAP_SHARED, map_fd, map->base);
#endif
if (map->memory == MAP_FAILED) { if (map->memory == MAP_FAILED) {
err = errno; err = errno;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment