[PATCH 4/6] switch to modern pci_device_map_range API

Jonathan Nieder jrnieder at gmail.com
Mon Feb 20 23:47:36 PST 2012


Ever since it was introduced in libpciaccess 0.10.0 four years ago,
pci_device_map_range has been the preferred way to map a PCI region
and pci_device_map_region has been a deprecated backward-compatibility
shim.  Switch over.  No functional change intended.

Noticed by gcc -Wdeprecated-declarations.

Signed-off-by: Jonathan Nieder <jrnieder at gmail.com>
---
 avivotool.c  |   37 +++++++++++++++++++------------------
 configure.ac |    2 +-
 radeonreg.c  |   22 +++++++++++++---------
 radeontool.c |   29 ++++++++++++++++-------------
 4 files changed, 49 insertions(+), 41 deletions(-)

diff --git a/avivotool.c b/avivotool.c
index 62f96a8e..1871fa93 100644
--- a/avivotool.c
+++ b/avivotool.c
@@ -57,7 +57,7 @@ int reg_type[0x8001];
 /* Not the address but what it points to is volatile. */
 struct pci_device *avivo_device = NULL;
 RADEONCardInfo *card_info = NULL;
-int ctrl_region = -1, fb_region = -1;
+pciaddr_t fb_base;
 unsigned char * volatile ctrl_mem;
 unsigned char * volatile fb_mem;
 
@@ -567,13 +567,11 @@ void radeon_output_set(char *output, char *status)
             /* Select graphics mode? */
             SET_REG(0x00000330, 0x00010600);
             SET_REG(0x00000338, 0x00000400);
-            SET_REG(AVIVO_D1GRPH_PRIMARY_SURFACE_ADDRESS,
-                    avivo_device->regions[fb_region].base_addr);
+            SET_REG(AVIVO_D1GRPH_PRIMARY_SURFACE_ADDRESS, fb_base);
             /* These modelines are all hardcoded for my 1280x1024;
              * adjust to suit. */
             SET_REG(AVIVO_D1GRPH_SECONDARY_SURFACE_ADDRESS,
-                    avivo_device->regions[fb_region].base_addr +
-                     (1280 * 1024 * 4)); 
+                    fb_base + 1280 * 1024 * 4);
 
             SET_REG(AVIVO_D1GRPH_X_END, 1280);
             SET_REG(AVIVO_D1GRPH_Y_END, 1024);
@@ -651,7 +649,7 @@ int radeon_get_fb_params(char *crtc, int write, unsigned long *location, int *le
         return 0;
     }
 
-    *location -= avivo_device->regions[fb_region].base_addr;
+    *location -= fb_base;
     *location += (unsigned long) fb_mem;
 #endif
     return 1;
@@ -1797,6 +1795,8 @@ static int map_radeon_mem(void)
 #endif
     struct pci_device_iterator *iter;
     struct pci_device *device;
+    pciaddr_t ctrl_base, ctrl_size = 0;
+    pciaddr_t fb_size = 0;
     int i = 0;
 
     if (pci_system_init() != 0) {
@@ -1849,24 +1849,26 @@ static int map_radeon_mem(void)
                 if (device->regions[i].size == 64 * 1024 ||
                     device->regions[i].size == 128 * 1024 ||
                     device->regions[i].size == 256 * 1024) {
-                    if (ctrl_region != -1) {
+                    if (ctrl_size) {
                         printf("cannot distinguish ctrl region\n");
                         return -1;
                     }
-                    ctrl_region = i;
+                    ctrl_base = device->regions[i].base_addr;
+                    ctrl_size = device->regions[i].size;
                 } else if (device->regions[i].size >= 128 * 1024 * 1024) {
-                    if (fb_region != -1) {
+                    if (fb_size) {
                         printf("cannot distinguish fb region\n");
                         return -1;
                     }
-                    fb_region = i;
+                    fb_base = device->regions[i].base_addr;
+                    fb_size = device->regions[i].size;
                 }
             }
-            if (ctrl_region == -1) {
+            if (!ctrl_size) {
                 printf("cannot find ctrl region\n");
                 return -1;
             }
-            if (fb_region == -1) {
+            if (!fb_size) {
                 printf("cannot find fb region\n");
                 return -1;
             }
@@ -1882,16 +1884,15 @@ static int map_radeon_mem(void)
       return -1;
     }
       
-    if (pci_device_map_region(avivo_device, ctrl_region, 1) != 0) {
+    if (pci_device_map_range(avivo_device, ctrl_base, ctrl_size,
+			     PCI_DEV_MAP_FLAG_WRITABLE, (void **) &ctrl_mem)) {
         fprintf(stderr, "error: mapping ctrl region\n");
         return -1;
     }
-    ctrl_mem = avivo_device->regions[ctrl_region].memory;
 
-    if (pci_device_map_region(avivo_device, fb_region, 1) == 0)
-    	fb_mem = avivo_device->regions[fb_region].memory;
-    else
-	fb_mem = NULL;
+    if (pci_device_map_range(avivo_device, fb_base, fb_size,
+			     PCI_DEV_MAP_FLAG_WRITABLE, (void **) &fb_mem))
+        fb_mem = NULL;
 
     pci_iterator_destroy(iter);
 
diff --git a/configure.ac b/configure.ac
index 45a5237f..c71f0217 100644
--- a/configure.ac
+++ b/configure.ac
@@ -30,6 +30,6 @@ AC_DISABLE_STATIC
 AC_PROG_CC
 AC_PROG_INSTALL
 
-PKG_CHECK_MODULES(LIBPCIACCESS, pciaccess)
+PKG_CHECK_MODULES(LIBPCIACCESS, [pciaccess >= 0.10.0])
 
 AC_OUTPUT([Makefile])
diff --git a/radeonreg.c b/radeonreg.c
index 4d016fd6..78c20fb0 100644
--- a/radeonreg.c
+++ b/radeonreg.c
@@ -40,7 +40,6 @@ int skip;
 /* Not the address but what it points to is volatile. */
 struct pci_device *avivo_device = NULL;
 RADEONCardInfo *card_info = NULL;
-unsigned int ctrl_region, fb_region;
 unsigned char * volatile ctrl_mem;
 unsigned char * volatile fb_mem;
 
@@ -365,6 +364,8 @@ static int map_radeon_mem(void)
 #endif
     struct pci_device_iterator *iter;
     struct pci_device *device;
+    pciaddr_t ctrl_base, ctrl_size = 0;
+    pciaddr_t fb_base, fb_size = 0;
     int i = 0;
 
     if (pci_system_init() != 0)
@@ -399,8 +400,10 @@ static int map_radeon_mem(void)
 		    card_info = &RADEONCards[i];
 	    }
 
-	    fb_region = 0;
-	    ctrl_region = 2;
+            fb_base = device->regions[0].base_addr;
+            fb_size = device->regions[0].size;
+            ctrl_base = device->regions[2].base_addr;
+            ctrl_size = device->regions[2].size;
             avivo_device = device;
             if(skip-- == 0) {
                 break;
@@ -413,14 +416,15 @@ static int map_radeon_mem(void)
       return -1;
     }
 
-    if (pci_device_map_region(avivo_device, ctrl_region, 1) != 0)
+    if (!ctrl_size ||
+        pci_device_map_range(avivo_device, ctrl_base, ctrl_size,
+			     PCI_DEV_MAP_FLAG_WRITABLE, (void **) &ctrl_mem))
         die("mapping ctrl region");
-    ctrl_mem = avivo_device->regions[ctrl_region].memory;
 
-    if (pci_device_map_region(avivo_device, fb_region, 1) == 0)
-    	fb_mem = avivo_device->regions[fb_region].memory;
-    else
-	fb_mem = NULL;
+    if (!fb_size ||
+        pci_device_map_range(avivo_device, fb_base, fb_size,
+			     PCI_DEV_MAP_FLAG_WRITABLE, (void **) &fb_mem))
+        fb_mem = NULL;
 
     pci_iterator_destroy(iter);
 
diff --git a/radeontool.c b/radeontool.c
index d2592545..3b3c72e5 100644
--- a/radeontool.c
+++ b/radeontool.c
@@ -33,7 +33,6 @@ int skip = 0;
 /* Not the address but what it points to is volatile. */
 struct pci_device *avivo_device = NULL;
 unsigned char * volatile radeon_cntl_mem;
-int ctrl_region = -1, fb_region = -1;
 unsigned char * volatile fb_mem;
 unsigned char * volatile ctrl_mem;
 static void radeon_rom_legacy_mmio_table(unsigned char *bios, int offset);
@@ -917,6 +916,9 @@ static void map_radeon_cntl_mem(void)
     struct pci_slot_match match;
     struct pci_device_iterator *iter;
     struct pci_device *device;
+    pciaddr_t ctrl_base, ctrl_size = 0;
+    pciaddr_t fb_base, fb_size = 0;
+
     int i = 0;
 
     if (pci_system_init() != 0)
@@ -945,18 +947,20 @@ static void map_radeon_cntl_mem(void)
             for (i = 0; i < 6; i++) {
                 if (device->regions[i].size >= 16 * 1024 &&
                     device->regions[i].size <= 64 * 1024) {
-                    if (ctrl_region != -1)
+                    if (ctrl_size)
                         die("cannot distinguish ctrl region");
-                    ctrl_region = i;
+                    ctrl_base = device->regions[i].base_addr;
+                    ctrl_size = device->regions[i].size;
                 } else if (device->regions[i].size >= 64 * 1024 * 1024) {
-                    if (fb_region != -1)
+                    if (fb_size)
                         die("cannot distinguish fb region");
-                    fb_region = i;
+                    fb_base = device->regions[i].base_addr;
+                    fb_size = device->regions[i].size;
                 }
             }
-            if (ctrl_region == -1)
+            if (!ctrl_size)
                 die("cannot find ctrl region");
-            if (fb_region == -1)
+            if (!fb_size)
                 die("cannot find fb region");
             avivo_device = device;
             break;
@@ -966,14 +970,13 @@ static void map_radeon_cntl_mem(void)
     if (!avivo_device)
         die("cannot find Radeon device");
 
-    if (pci_device_map_region(avivo_device, ctrl_region, 1) != 0)
+    if (pci_device_map_range(avivo_device, ctrl_base, ctrl_size,
+			     PCI_DEV_MAP_FLAG_WRITABLE, (void **) &ctrl_mem))
         die("mapping ctrl region");
-    ctrl_mem = avivo_device->regions[ctrl_region].memory;
 
-    if (pci_device_map_region(avivo_device, fb_region, 1) == 0)
-    	fb_mem = avivo_device->regions[fb_region].memory;
-    else
-	fb_mem = NULL;
+    if (pci_device_map_range(avivo_device, fb_base, fb_size,
+			     PCI_DEV_MAP_FLAG_WRITABLE, (void **) &fb_mem))
+        fb_mem = NULL;
 
     pci_iterator_destroy(iter);
 
-- 
1.7.9.1



More information about the xorg-driver-ati mailing list