]> mj.ucw.cz Git - pciutils.git/commitdiff
Replaced `buffer' access method by a real cache.
authorMartin Mares <mj@ucw.cz>
Sun, 24 Jan 1999 21:35:35 +0000 (21:35 +0000)
committerMartin Mares <mj@ucw.cz>
Fri, 5 May 2006 12:10:02 +0000 (14:10 +0200)
lib/Makefile
lib/access.c
lib/buffer.c [deleted file]
lib/pci.h

index 6138fd98619c802e85b177f6424f5790b47c67de..0752908a5c3484f017aef96257936f5d82a6f8dd 100644 (file)
@@ -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 <mj@atrey.karlin.mff.cuni.cz>
 
 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
index cd7ce1202624d9644884b992523d578cd4f770c8..343abd8446855282cca1264bb679d1704970e36e 100644 (file)
@@ -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 (file)
index 9e62802..0000000
+++ /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 <mj@atrey.karlin.mff.cuni.cz>
- *
- *     Can be freely distributed and used under the terms of the GNU GPL.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-
-#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;
-}
index 80ae5a100572aed248d08443bc5dbe6ff5f3e59e..71154df59be1ab75c9665cc9a09aed755197185a 100644 (file)
--- 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