From 87ec7de307ab5bd395d01cdb4f8fdf231d9e769e Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Fri, 12 Jan 2007 13:13:27 -0800 Subject: [PATCH] Fix many warnings and bugs in the freebsd implementation. With this, scanpci gives partially-sane results. --- src/common_init.c | 2 -- src/freebsd_pci.c | 33 ++++++++++++++++++++++++++++----- src/pciaccess_private.h | 3 +++ 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/common_init.c b/src/common_init.c index f8e213a..109bd74 100644 --- a/src/common_init.c +++ b/src/common_init.c @@ -35,8 +35,6 @@ #include "pciaccess.h" #include "pciaccess_private.h" -extern int pci_system_linux_sysfs_create( void ); - struct pci_system * pci_sys; /** diff --git a/src/freebsd_pci.c b/src/freebsd_pci.c index f2ebdfb..8b846e8 100644 --- a/src/freebsd_pci.c +++ b/src/freebsd_pci.c @@ -33,6 +33,7 @@ #include #include +#include #include #include #include @@ -128,6 +129,10 @@ pci_device_freebsd_read( struct pci_device * dev, void * data, while ( size > 0 ) { int toread = (size < 4) ? size : 4; + /* Only power of two allowed. */ + if (toread == 3) + toread = 2; + io.pi_reg = offset; io.pi_width = toread; @@ -137,10 +142,12 @@ pci_device_freebsd_read( struct pci_device * dev, void * data, memcpy(data, &io.pi_data, toread ); offset += toread; - data += toread; + data = (char *)data + toread; size -= toread; *bytes_read += toread; } + + return 0; } @@ -167,17 +174,29 @@ pci_device_freebsd_write( struct pci_device * dev, const void * data, return errno; offset += towrite; - data += towrite; + data = (char *)data + towrite; size -= towrite; *bytes_written += towrite; } + + return 0; +} + +static int +pci_device_freebsd_probe( struct pci_device * dev ) +{ + /* Many of the fields were filled in during initial device enumeration. + * At this point, we need to fill in regions, rom_size, and irq. + */ + + return 0; } static const struct pci_system_methods freebsd_pci_methods = { .destroy = NULL, /* XXX: free memory */ .destroy_device = NULL, .read_rom = NULL, /* XXX: Fill me in */ - .probe = NULL, /* XXX: Fill me in */ + .probe = pci_device_freebsd_probe, .map = pci_device_freebsd_map, .unmap = pci_device_freebsd_unmap, .read = pci_device_freebsd_read, @@ -193,7 +212,6 @@ pci_system_freebsd_create( void ) { struct pci_conf_io pciconfio; struct pci_conf pciconf[255]; - struct freebsd_pci_system *freebsd_pci_sys; int pcidev; int i; @@ -213,7 +231,7 @@ pci_system_freebsd_create( void ) freebsd_pci_sys->pcidev = pcidev; /* Probe the list of devices known by the system */ - bzero( &pciconf, sizeof( struct pci_conf_io ) ); + bzero( &pciconfio, sizeof( struct pci_conf_io ) ); pciconfio.match_buf_len = sizeof(pciconf); pciconfio.matches = pciconf; @@ -241,6 +259,11 @@ pci_system_freebsd_create( void ) pci_sys->devices[ i ].base.bus = p->pc_sel.pc_bus; pci_sys->devices[ i ].base.dev = p->pc_sel.pc_dev; pci_sys->devices[ i ].base.func = p->pc_sel.pc_func; + pci_sys->devices[ i ].base.vendor_id = p->pc_vendor; + pci_sys->devices[ i ].base.device_id = p->pc_device; + pci_sys->devices[ i ].base.subvendor_id = p->pc_subvendor; + pci_sys->devices[ i ].base.device_class = (uint32_t)p->pc_class << 16 | + (uint32_t)p->pc_subclass << 8 | (uint32_t)p->pc_progif; } return 0; diff --git a/src/pciaccess_private.h b/src/pciaccess_private.h index 700036f..b23e589 100644 --- a/src/pciaccess_private.h +++ b/src/pciaccess_private.h @@ -96,3 +96,6 @@ struct pci_system { }; extern struct pci_system * pci_sys; + +extern int pci_system_linux_sysfs_create( void ); +extern int pci_system_freebsd_create( void ); -- 2.7.4