[PATCH 07/10] switch to modern pci_device_map_range API
Jonathan Nieder
jrnieder at gmail.com
Fri Feb 24 19:57:02 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 | 31 ++++++++++++++-----------------
configure.ac | 2 +-
radeonreg.c | 22 ++++++++++------------
radeontool.c | 22 ++++++++++------------
4 files changed, 35 insertions(+), 42 deletions(-)
diff --git a/avivotool.c b/avivotool.c
index bc827b37..2f7d4e57 100644
--- a/avivotool.c
+++ b/avivotool.c
@@ -55,9 +55,8 @@ int reg_type[0x8001];
/* *ctrl_mem is mapped to the actual device's memory mapped control area. */
/* 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;
+pciaddr_t fb_base;
unsigned char * volatile ctrl_mem;
unsigned char * volatile fb_mem;
@@ -567,13 +566,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 +648,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 +1794,7 @@ static int map_radeon_mem(void)
#endif
struct pci_device_iterator *iter;
struct pci_device *device;
+ pciaddr_t fb_size, ctrl_base, ctrl_size;
int i = 0;
if (pci_system_init() != 0) {
@@ -1858,20 +1856,19 @@ static int map_radeon_mem(void)
return -1;
}
- fb_region = 0;
- ctrl_region = 2;
- avivo_device = device;
-
- if (pci_device_map_region(avivo_device, ctrl_region, 1) != 0) {
+ ctrl_base = device->regions[2].base_addr;
+ ctrl_size = device->regions[2].size;
+ if (!ctrl_size || pci_device_map_range(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;
+ fb_base = device->regions[0].base_addr;
+ fb_size = device->regions[0].size;
+ if (!fb_size || pci_device_map_range(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 2223cee2..7b763518 100644
--- a/radeonreg.c
+++ b/radeonreg.c
@@ -38,9 +38,7 @@ int skip;
/* *ctrl_mem is mapped to the actual device's memory mapped control area. */
/* 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 +363,7 @@ static int map_radeon_mem(void)
#endif
struct pci_device_iterator *iter;
struct pci_device *device;
+ pciaddr_t fb_base, fb_size, ctrl_base, ctrl_size;
int i = 0;
if (pci_system_init() != 0)
@@ -411,18 +410,17 @@ static int map_radeon_mem(void)
card_info = &RADEONCards[i];
}
- fb_region = 0;
- ctrl_region = 2;
- avivo_device = device;
-
- if (pci_device_map_region(avivo_device, ctrl_region, 1) != 0)
+ ctrl_base = device->regions[2].base_addr;
+ ctrl_size = device->regions[2].size;
+ if (!ctrl_size || pci_device_map_range(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;
+ fb_base = device->regions[0].base_addr;
+ fb_size = device->regions[0].size;
+ if (!fb_size || pci_device_map_range(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 cb0d12d2..dbab7631 100644
--- a/radeontool.c
+++ b/radeontool.c
@@ -31,9 +31,7 @@ int skip = 0;
/* *radeon_cntl_mem is mapped to the actual device's memory mapped control area. */
/* 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 +915,7 @@ static void map_radeon_cntl_mem(void)
struct pci_slot_match match;
struct pci_device_iterator *iter;
struct pci_device *device;
+ pciaddr_t fb_base, fb_size, ctrl_base, ctrl_size;
int i = 0;
if (pci_system_init() != 0)
@@ -948,18 +947,17 @@ static void map_radeon_cntl_mem(void)
if (!device)
die("cannot find Radeon device");
- fb_region = 0;
- ctrl_region = 2;
- avivo_device = device;
-
- if (pci_device_map_region(avivo_device, ctrl_region, 1) != 0)
+ ctrl_base = device->regions[2].base_addr;
+ ctrl_size = device->regions[2].size;
+ if (!ctrl_size || pci_device_map_range(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;
+ fb_base = device->regions[0].base_addr;
+ fb_size = device->regions[0].size;
+ if (!fb_size || pci_device_map_range(device, fb_base, fb_size,
+ PCI_DEV_MAP_FLAG_WRITABLE, (void **) &fb_mem))
+ fb_mem = NULL;
pci_iterator_destroy(iter);
--
1.7.9.2
More information about the xorg-driver-ati
mailing list