From 3430bafe5ee582f14bc51fb3d27f29abce68c075 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 24 Jan 1999 21:35:35 +0000 Subject: [PATCH] Replaced `buffer' access method by a real cache. --- lib/Makefile | 4 ++-- lib/access.c | 20 ++++++++++++++++++-- lib/buffer.c | 53 ---------------------------------------------------- lib/pci.h | 10 ++++------ 4 files changed, 24 insertions(+), 63 deletions(-) delete mode 100644 lib/buffer.c diff --git a/lib/Makefile b/lib/Makefile index 6138fd9..0752908 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,10 +1,10 @@ -# $Id: Makefile,v 1.1 1999/01/22 21:05:10 mj Exp $ +# $Id: Makefile,v 1.2 1999/01/24 21:35:35 mj Exp $ # Makefile for The PCI Library # (c) 1999 Martin Mares include config.mk -OBJS=access.o generic.o dump.o names.o filter.o buffer.o +OBJS=access.o generic.o dump.o names.o filter.o INCL=internal.h pci.h config.h ifdef HAVE_PM_LINUX_PROC diff --git a/lib/access.c b/lib/access.c index cd7ce12..343abd8 100644 --- a/lib/access.c +++ b/lib/access.c @@ -1,5 +1,5 @@ /* - * $Id: access.c,v 1.1 1999/01/22 21:05:12 mj Exp $ + * $Id: access.c,v 1.2 1999/01/24 21:35:35 mj Exp $ * * The PCI Library -- User Access * @@ -217,7 +217,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 +258,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,6 +286,11 @@ 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); } @@ -297,3 +306,10 @@ pci_fill_info(struct pci_dev *d, int flags) d->methods->fill_info(d, flags & ~d->known_fields); d->known_fields |= flags; } + +void +pci_setup_cache(struct pci_dev *d, byte *cache, int len) +{ + d->cache = cache; + d->cache_len = len; +} diff --git a/lib/buffer.c b/lib/buffer.c deleted file mode 100644 index 9e62802..0000000 --- a/lib/buffer.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * $Id: buffer.c,v 1.1 1999/01/22 21:05:14 mj Exp $ - * - * The PCI Library -- Buffered Access - * - * Copyright (c) 1997--1999 Martin Mares - * - * Can be freely distributed and used under the terms of the GNU GPL. - */ - -#include -#include -#include -#include - -#include "internal.h" - -static int -buff_read(struct pci_dev *d, int pos, byte *buf, int len) -{ - memcpy(buf, (byte *)d->aux + pos, len); - return 1; -} - -static int -buff_write(struct pci_dev *d, int UNUSED pos, byte * UNUSED buf, int UNUSED len) -{ - d->access->error("buffer: Writing to configuration space not supported."); - return 0; -} - -static struct pci_methods pm_buffer = { - "Buffer", - NULL, /* config */ - NULL, /* Shall not be called */ - NULL, /* No init nor cleanup */ - NULL, - NULL, /* No scanning */ - pci_generic_fill_info, - buff_read, - buff_write, - NULL, /* init_dev */ - NULL /* cleanup_dev */ -}; - -void -pci_setup_buffer(struct pci_dev *d, byte *buf) -{ - if (d->methods->cleanup_dev) - d->methods->cleanup_dev(d); - d->methods = &pm_buffer; - d->aux = buf; -} diff --git a/lib/pci.h b/lib/pci.h index 80ae5a1..71154df 100644 --- a/lib/pci.h +++ b/lib/pci.h @@ -1,5 +1,5 @@ /* - * $Id: pci.h,v 1.1 1999/01/22 21:05:34 mj Exp $ + * $Id: pci.h,v 1.2 1999/01/24 21:35:36 mj Exp $ * * The PCI Library * @@ -100,6 +100,8 @@ struct pci_dev { /* Fields used internally: */ struct pci_access *access; struct pci_methods *methods; + byte *cache; /* Cached information */ + int cache_len; int known_fields; /* Set of info fields that is already known */ int hdrtype; /* Direct methods: header type */ void *aux; /* Auxillary data */ @@ -122,11 +124,7 @@ void pci_fill_info(struct pci_dev *, int flags); /* Fill in device information * #define PCI_FILL_ROM_BASE 8 #define PCI_FILL_RESCAN 0x10000 -/* - * Buffered access - */ - -void pci_setup_buffer(struct pci_dev *, byte *buf); +void pci_setup_cache(struct pci_dev *, byte *cache, int len); /* * Filters -- 2.39.2