File radeontool-get-rid-of-lspci.diff of Package radeontool
--- radeontool.c 2006/02/22 11:07:50 1.3
+++ radeontool.c 2006/03/08 00:37:25
@@ -21,6 +21,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
+#include <pci/pci.h>
#include "radeon_reg.h"
@@ -231,7 +232,7 @@ void radeon_cmd_stretch(char *param)
radeon_set(RADEON_FP_VERT_STRETCH,"RADEON_FP_VERT_STRETCH",fp_vert_stretch);
}
-
+#if 0
/* Here we fork() and exec() the lspci command to look for the Radeon hardware address. */
static void map_radeon_cntl_mem(void)
{
@@ -317,6 +318,62 @@ We need to look through it to find the s
printf("Radeon found. Base control address is %x.\n",base);
radeon_cntl_mem = map_device_memory(base,0x2000);
}
+#else
+static u32
+conf2long(unsigned char *c, unsigned int p)
+{
+ return c[p] | (c[p+1] << 8) | (c[p+2] << 16) | (c[p+3] << 24);
+}
+
+static void map_radeon_cntl_mem(void)
+{
+ struct pci_access *pacc;
+ struct pci_dev *dev;
+ unsigned int class;
+ int i;
+ int base = -1;
+ unsigned char *config;
+
+ config = malloc(64);
+ if (!config)
+ fatal("malloc(64) failed\n");
+ pacc = pci_alloc();
+ pci_init(pacc);
+ pci_scan_bus(pacc);
+ for(dev=pacc->devices; dev; dev=dev->next) { /* Iterate over all devices */
+ pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES);/* Fill in header info we need */
+ class = pci_read_word(dev, PCI_CLASS_DEVICE); /* Read config register directly */
+ if (dev->vendor_id == 0x1002 && class == 0x300) { /* ATI && Graphics card */
+ if (debug)
+ printf("Found: %02x:%02x.%d vendor=%04x device=%04x class=%04x\n",
+ dev->bus, dev->dev, dev->func, dev->vendor_id, dev->device_id, class);
+ if (skip-- < 1) {
+ pci_read_block(dev, 0, config, 64);
+ for (i=0; i<6; i++){
+ u32 flag = conf2long(config, PCI_BASE_ADDRESS_0 + 4*i);
+ if (flag & PCI_BASE_ADDRESS_SPACE_IO) /* I/O-Ports, not memory */
+ continue;
+ /* the original code parsed lspci for "emory" and "K", so it
+ * has to be at least 1K and less than 1M
+ */
+ if (dev->size[i] >=1024 && dev->size[i] < 1024*1024) {
+ base = dev->base_addr[i];
+ goto found;
+ }
+ }
+ }
+ }
+ }
+ found:
+ pci_cleanup(pacc);
+ free(config);
+ if (base == -1)
+ fatal("Radeon not found.\n");
+ if (debug)
+ printf("Radeon found. Base control address is %x.\n",base);
+ radeon_cntl_mem = map_device_memory(base,0x2000);
+}
+#endif
int main(int argc,char *argv[])
{
@@ -328,7 +385,7 @@ int main(int argc,char *argv[])
debug=1;
argv++; argc--;
};
- if(strcmp(argv[1],"--skip=") == 0) {
+ if(strncmp(argv[1],"--skip=",7) == 0) {
skip=atoi(argv[1]+7);
argv++; argc--;
};