X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Faccess.c;h=5683eac8dd96a7b3e1b9c493024e155c227af2dc;hb=087e22e7bfdfc3eb0664ac9cca571c3858d838c9;hp=cd7ce1202624d9644884b992523d578cd4f770c8;hpb=727ce158868ed101006ecc5d3dd3faede927165c;p=pciutils.git diff --git a/lib/access.c b/lib/access.c index cd7ce12..5683eac 100644 --- a/lib/access.c +++ b/lib/access.c @@ -1,9 +1,7 @@ /* - * $Id: access.c,v 1.1 1999/01/22 21:05:12 mj Exp $ - * * The PCI Library -- User Access * - * Copyright (c) 1997--1999 Martin Mares + * Copyright (c) 1997--2003 Martin Mares * * Can be freely distributed and used under the terms of the GNU GPL. */ @@ -17,24 +15,39 @@ static struct pci_methods *pci_methods[PCI_ACCESS_MAX] = { NULL, -#ifdef HAVE_PM_LINUX_PROC - &pm_linux_proc, +#ifdef PCI_HAVE_PM_LINUX_SYSFS + &pm_linux_sysfs, #else NULL, #endif -#ifdef HAVE_PM_SYSCALLS - &pm_syscalls, +#ifdef PCI_HAVE_PM_LINUX_PROC + &pm_linux_proc, #else NULL, #endif -#ifdef HAVE_PM_INTEL_CONF +#ifdef PCI_HAVE_PM_INTEL_CONF &pm_intel_conf1, &pm_intel_conf2, #else NULL, NULL, #endif -#ifdef HAVE_PM_DUMP +#ifdef PCI_HAVE_PM_FBSD_DEVICE + &pm_fbsd_device, +#else + NULL, +#endif +#ifdef PCI_HAVE_PM_AIX_DEVICE + &pm_aix_device, +#else + NULL, +#endif +#ifdef PCI_HAVE_PM_NBSD_LIBPCI + &pm_nbsd_libpci, +#else + NULL, +#endif +#ifdef PCI_HAVE_PM_DUMP &pm_dump, #else NULL, @@ -48,7 +61,7 @@ pci_alloc(void) int i; bzero(a, sizeof(*a)); - a->id_file_name = PATH_PCI_IDS; + a->id_file_name = PCI_PATH_IDS; for(i=0; iconfig) pci_methods[i]->config(a); @@ -106,7 +119,7 @@ pci_generic_debug(char *msg, ...) } static void -pci_null_debug(char * UNUSED msg, ...) +pci_null_debug(char *msg UNUSED, ...) { } @@ -139,6 +152,7 @@ pci_init(struct pci_access *a) { a->debug("...OK\n"); a->methods = pci_methods[i]; + a->method = i; break; } a->debug("...No.\n"); @@ -180,6 +194,7 @@ pci_alloc_dev(struct pci_access *a) bzero(d, sizeof(*d)); d->access = a; d->methods = a->methods; + d->hdrtype = -1; if (d->methods->init_dev) d->methods->init_dev(d); return d; @@ -195,10 +210,11 @@ pci_link_dev(struct pci_access *a, struct pci_dev *d) } struct pci_dev * -pci_get_dev(struct pci_access *a, int bus, int dev, int func) +pci_get_dev(struct pci_access *a, int domain, int bus, int dev, int func) { struct pci_dev *d = pci_alloc_dev(a); + d->domain = domain; d->bus = bus; d->dev = dev; d->func = func; @@ -217,7 +233,9 @@ pci_read_data(struct pci_dev *d, void *buf, int pos, int len) { if (pos & (len-1)) d->access->error("Unaligned read: pos=%02x, len=%d", pos, len); - if (!d->methods->read(d, pos, buf, len)) + if (pos + len <= d->cache_len) + memcpy(buf, d->cache + pos, len); + else if (!d->methods->read(d, pos, buf, len)) memset(buf, 0xff, len); } @@ -256,6 +274,8 @@ pci_write_data(struct pci_dev *d, void *buf, int pos, int len) { if (pos & (len-1)) d->access->error("Unaligned write: pos=%02x,len=%d", pos, len); + if (pos + len <= d->cache_len) + memcpy(d->cache + pos, buf, len); return d->methods->write(d, pos, buf, len); } @@ -282,10 +302,15 @@ pci_write_long(struct pci_dev *d, int pos, u32 data) int pci_write_block(struct pci_dev *d, int pos, byte *buf, int len) { + if (pos < d->cache_len) + { + int l = (pos + len >= d->cache_len) ? (d->cache_len - pos) : len; + memcpy(d->cache + pos, buf, l); + } return d->methods->write(d, pos, buf, len); } -void +int pci_fill_info(struct pci_dev *d, int flags) { if (flags & PCI_FILL_RESCAN) @@ -294,6 +319,13 @@ pci_fill_info(struct pci_dev *d, int flags) d->known_fields = 0; } if (flags & ~d->known_fields) - d->methods->fill_info(d, flags & ~d->known_fields); - d->known_fields |= flags; + d->known_fields |= d->methods->fill_info(d, flags & ~d->known_fields); + return d->known_fields; +} + +void +pci_setup_cache(struct pci_dev *d, byte *cache, int len) +{ + d->cache = cache; + d->cache_len = len; }