[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Lost] + cdi: Helferfunktionen für Speicher von PCI-Geraeten, Indizes für PCI-Resourcen



Das hier fügt 1. einen Index zu den PCI-Resourcen hinzu, damit man sie einfacher unterscheiden kann, und 2. fügt es Funktionen für die Verwaltung der Resourcen (vor allem das Alloziieren des Speichers) hinzu.

Mathias

From d860c11d5a0b89df9d9dc3b28901234699902345 Mon Sep 17 00:00:00 2001
From: Mathias Gottschlag <mathias-go@xxxxxx>
Date: Sat, 11 Oct 2008 00:12:07 +0200
Subject: [PATCH] =?utf-8?q?+=20cdi:=20Helferfunktionen=20f=C3=BCr=20Speicher=20von=20PCI-Ger=C3=A4ten,=20Indizes=20f=C3=BCr=20PCI-Resourcen?=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit

---
 src/modules/cdi/include/cdi/pci.h |   20 +++++++++++++--
 src/modules/cdi/lib/pci.c         |   47 +++++++++++++++++++++++++++++++++++++
 2 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/src/modules/cdi/include/cdi/pci.h b/src/modules/cdi/include/cdi/pci.h
index 81eacb4..eb8a60f 100644
--- a/src/modules/cdi/include/cdi/pci.h
+++ b/src/modules/cdi/include/cdi/pci.h
@@ -37,9 +37,11 @@ typedef enum {
 } cdi_res_t;
 
 struct cdi_pci_resource {
-    cdi_res_t   type;
-    uintptr_t   start;
-    size_t      length;
+    cdi_res_t    type;
+    uintptr_t    start;
+    size_t       length;
+    unsigned int index;
+    void*        address;
 };
 
 
@@ -58,6 +60,18 @@ void cdi_pci_device_destroy(struct cdi_pci_device* device);
  * Reserviert die IO-Ports des PCI-Geraets fuer den Treiber
  */
 void cdi_pci_alloc_ioports(struct cdi_pci_device* device);
+/**
+ * Gibt die IO-Ports des PCI-Geraets frei
+ */
+void cdi_pci_free_ioports(struct cdi_pci_device* device);
+/**
+ * Reserviert den MMIO-Speicher des PCI-Geraets fuer den Treiber
+ */
+void cdi_pci_alloc_memory(struct cdi_pci_device* device);
+/**
+ * Gibt den MMIO-Speicher des PCI-Geraets frei
+ */
+void cdi_pci_free_memory(struct cdi_pci_device* device);
 
 #endif
 
diff --git a/src/modules/cdi/lib/pci.c b/src/modules/cdi/lib/pci.c
index c64f15a..f92e057 100644
--- a/src/modules/cdi/lib/pci.c
+++ b/src/modules/cdi/lib/pci.c
@@ -53,12 +53,15 @@ static struct cdi_pci_device* read_pci_device(char* filename)
     // Ressourcen hinzufuegen
     struct pci_resource res;
     struct cdi_pci_resource* cdi_res;
+    int index = 0;
     while (!feof(f)) {
         if (fread(&res, sizeof(res), 1, f)) {
             
             cdi_res = malloc(sizeof(*cdi_res));
             cdi_res->start = res.start;
             cdi_res->length = res.length;
+            cdi_res->index = index++;
+            cdi_res->address = 0;
 
             switch (res.type) {
                 case PCI_RESOURCE_MEM:
@@ -141,3 +144,47 @@ void cdi_pci_alloc_ioports(struct cdi_pci_device* device)
         }
     }
 }
+/**
+ * Gibt die IO-Ports des PCI-Geraets frei
+ */
+void cdi_pci_free_ioports(struct cdi_pci_device* device)
+{
+    struct cdi_pci_resource* res;
+    int i = 0;
+
+    for (i = 0; (res = cdi_list_get(device->resources, i)); i++) {
+        if (res->type == CDI_PCI_IOPORTS) {
+            release_ports(res->start, res->length);
+        }
+    }
+}
+/**
+ * Reserviert den MMIO-Speicher des PCI-Geraets fuer den Treiber
+ */
+void cdi_pci_alloc_memory(struct cdi_pci_device* device)
+{
+    struct cdi_pci_resource* res;
+    int i = 0;
+
+    for (i = 0; (res = cdi_list_get(device->resources, i)); i++) {
+        if (res->type == CDI_PCI_IOPORTS) {
+            res->address = mem_allocate_physical(res->length, res->start, 0);
+        }
+    }
+}
+/**
+ * Gibt den MMIO-Speicher des PCI-Geraets frei
+ */
+void cdi_pci_free_memory(struct cdi_pci_device* device)
+{
+    struct cdi_pci_resource* res;
+    int i = 0;
+
+    for (i = 0; (res = cdi_list_get(device->resources, i)); i++) {
+        if (res->type == CDI_PCI_IOPORTS) {
+            mem_free_physical(res->address, res->length);
+            res->address = 0;
+        }
+    }
+}
+
-- 
1.5.4.3