From toni at tyndur.org Mon Feb 1 00:56:30 2010 From: toni at tyndur.org (Antoine Kaufmann) Date: Mon, 1 Feb 2010 00:56:30 +0100 Subject: [tyndur-devel] [PATCH] kernel2: Timer duerfen eax nicht kaputtmachen In-Reply-To: <1264967486-7761-1-git-send-email-kevin@tyndur.org> References: <1264967486-7761-1-git-send-email-kevin@tyndur.org> Message-ID: <20100131235630.GB4770@neo.geekcave.lan> On Sun, Jan 31 20:51, Kevin Wolf wrote: > ! kernel2: Timer fuehren einen RPC zum Prozess mit dem abgelaufenen > Timer aus und haben sich wie ein Syscall verhalten - das geht so weit, > dass sie in eax 0 als Rueckgabewert abgelegt haben. Das ist natuerlich > eher ungeschickt, wenn der Prozess eigentlich gar nicht selber nach > einem RPC gefragt hat, sondern sein eax noch braucht... > > Signed-off-by: Kevin Wolf Oha, das ist ja richtig mit sauber. Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From fmnssun at gmail.com Thu Feb 11 22:50:05 2010 From: fmnssun at gmail.com (Roman Muentener) Date: Thu, 11 Feb 2010 22:50:05 +0100 Subject: [tyndur-devel] [PATCH] Buffer ueberlauf bei h_addr_list[i] = NULL; Message-ID: <1265925005-3429-1-git-send-email-fmnssun@gmail.com> --- src/modules/lib/posix/net.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c index 9cc9b35..d1c4c6b 100644 --- a/src/modules/lib/posix/net.c +++ b/src/modules/lib/posix/net.c @@ -233,7 +233,7 @@ struct hostent* gethostbyname(const char* name) uint32_t* ip_q = malloc(sizeof(uint32_t)); *ip_q = string_to_ip(p); - h_addr_list = realloc(h_addr_list, sizeof(uint32_t*) * (i + 1)); + h_addr_list = realloc(h_addr_list, sizeof(uint32_t*) * (i + 2)); h_addr_list[i] = ip_q; i++; -- 1.6.0.4 From toni at tyndur.org Fri Feb 12 23:09:19 2010 From: toni at tyndur.org (Antoine Kaufmann) Date: Fri, 12 Feb 2010 23:09:19 +0100 Subject: [tyndur-devel] [PATCH] cdi: Behanndlung von Parititionen in CDI-Bibliothek verschoben In-Reply-To: <1263749873-2817-1-git-send-email-kevin@tyndur.org> References: <1263749873-2817-1-git-send-email-kevin@tyndur.org> Message-ID: <20100212220918.GA2715@neo.geekcave.lan> On Sun, Jan 17 18:37, Kevin Wolf wrote: > * cdi: Die Erkennung von Partitionen hat in ata nichts zu suchen. ata > stellt jetzt nur noch ein Geraet bereit und die CDI-Bibliothek erkennt > Paritionen darauf und erstellt die entsprechenden LostIO-Knoten. > > Signed-off-by: Kevin Wolf Ich glaube das sieht gut aus, wenn es dann auch noch funktioniert umso besser. ;-) Acked-by: Antoine Kaufmann -- Antoine Kaufmann -------------- nächster Teil -------------- Ein Dateianhang mit Binärdaten wurde abgetrennt... Dateiname : nicht verfügbar Dateityp : application/pgp-signature Dateigröße : 198 bytes Beschreibung: nicht verfügbar URL : From kevin at tyndur.org Sat Feb 13 00:25:45 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 13 Feb 2010 00:25:45 +0100 Subject: [tyndur-devel] [PATCH] Buffer ueberlauf bei h_addr_list[i] = NULL; In-Reply-To: <1265925005-3429-1-git-send-email-fmnssun@gmail.com> References: <1265925005-3429-1-git-send-email-fmnssun@gmail.com> Message-ID: <20100212232544.GA23684@silvanus> On Thu, Feb 11, 2010 at 10:50:05PM +0100, Roman Muentener wrote: > --- > src/modules/lib/posix/net.c | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) > > diff --git a/src/modules/lib/posix/net.c b/src/modules/lib/posix/net.c > index 9cc9b35..d1c4c6b 100644 > --- a/src/modules/lib/posix/net.c > +++ b/src/modules/lib/posix/net.c > @@ -233,7 +233,7 @@ struct hostent* gethostbyname(const char* name) > uint32_t* ip_q = malloc(sizeof(uint32_t)); > *ip_q = string_to_ip(p); > > - h_addr_list = realloc(h_addr_list, sizeof(uint32_t*) * (i + 1)); > + h_addr_list = realloc(h_addr_list, sizeof(uint32_t*) * (i + 2)); > h_addr_list[i] = ip_q; > i++; > > -- > 1.6.0.4 Danke, ist drin. From kevin at tyndur.org Sat Feb 13 22:12:16 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 13 Feb 2010 22:12:16 +0100 Subject: [tyndur-devel] [PATCH 0/5] cdi: mem.h Message-ID: <1266095541-6084-1-git-send-email-kevin@tyndur.org> Diese Serie enthält die CDI-Patches zur Einführung von mem.h und eine einfache Implementierung für tyndur. Die Implementierung ist alles andere als optimal, aber sie erfüllt die Spezifikation einigermaßen, so dass wir wenigstens schon einmal alle konformen Treiber bauen können. Kevin Wolf (5): cdi: Verwaltung von Speicherbereichen cdi: mem.h implementiert pcnet: Initialisierungsblock in eigene Funktion auslagern cdi: cdi_alloc_phys_mem/addr ersetzen cdi: Veraltete Funktionen entfernt src/modules/cdi/ata/device.c | 16 ++- src/modules/cdi/ata/device.h | 4 +- src/modules/cdi/ata/request.c | 2 +- src/modules/cdi/e1000/device.c | 19 ++- src/modules/cdi/e1000/device.h | 2 +- src/modules/cdi/include/cdi-osdep.h | 12 ++ src/modules/cdi/include/cdi/mem.h | 255 +++++++++++++++++++++++++++++ src/modules/cdi/include/cdi/misc.h | 23 --- src/modules/cdi/lib/mem.c | 215 ++++++++++++++++++++++++ src/modules/cdi/lib/misc.c | 39 ----- src/modules/cdi/ne2k/include/ne2k.h | 4 +- src/modules/cdi/ne2k/ne2k.c | 13 +- src/modules/cdi/pcnet/include/pcnet.h | 3 - src/modules/cdi/pcnet/pcnet.c | 127 +++++++++------ src/modules/cdi/rtl8139/include/rtl8139.h | 4 +- src/modules/cdi/rtl8139/rtl8139.c | 13 +- src/modules/cdi/sis900/device.c | 15 ++- src/modules/cdi/sis900/device.h | 2 +- 18 files changed, 625 insertions(+), 143 deletions(-) create mode 100644 src/modules/cdi/include/cdi/mem.h create mode 100644 src/modules/cdi/lib/mem.c From kevin at tyndur.org Sat Feb 13 22:12:17 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 13 Feb 2010 22:12:17 +0100 Subject: [tyndur-devel] [PATCH 1/5] cdi: Verwaltung von Speicherbereichen In-Reply-To: <1266095541-6084-1-git-send-email-kevin@tyndur.org> References: <1266095541-6084-1-git-send-email-kevin@tyndur.org> Message-ID: <1266095541-6084-2-git-send-email-kevin@tyndur.org> + cdi: Neuer Header mem.h, der Funktionen zur Verwaltung von Speicherbereichen enthaelt Signed-off-by: Kevin Wolf --- src/modules/cdi/include/cdi-osdep.h | 11 ++ src/modules/cdi/include/cdi/mem.h | 255 +++++++++++++++++++++++++++++++++++ 2 files changed, 266 insertions(+), 0 deletions(-) create mode 100644 src/modules/cdi/include/cdi/mem.h diff --git a/src/modules/cdi/include/cdi-osdep.h b/src/modules/cdi/include/cdi-osdep.h index 6187c32..0d052fe 100644 --- a/src/modules/cdi/include/cdi-osdep.h +++ b/src/modules/cdi/include/cdi-osdep.h @@ -68,4 +68,15 @@ typedef struct FILE* file; } cdi_dma_osdep; +/** + * \german + * OS-spezifische Daten fuer Speicherbereiche + * \endgerman + * \english + * OS-specific data for memory areas. + * \endenglish + */ +typedef struct { +} cdi_mem_osdep; + #endif diff --git a/src/modules/cdi/include/cdi/mem.h b/src/modules/cdi/include/cdi/mem.h new file mode 100644 index 0000000..08837f7 --- /dev/null +++ b/src/modules/cdi/include/cdi/mem.h @@ -0,0 +1,255 @@ +/* + * Copyright (c) 2010 Kevin Wolf + * + * This program is free software. It comes without any warranty, to + * the extent permitted by applicable law. You can redistribute it + * and/or modify it under the terms of the Do What The Fuck You Want + * To Public License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/projects/COPYING.WTFPL for more details. + */ + +#ifndef _CDI_MEM_H_ +#define _CDI_MEM_H_ + +#include +#include "cdi.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * \german + * Beschreibt Anforderungen an einen Speicherbereich + * \endgerman + * \english + * Describes requirements for a memory area + * \endenglish + */ +typedef enum { + /** + * \german + * Maske fuer ein Bitfeld, das das benoetige physische Alignment beschreibt + * (das geforderte Alignment ist 2^x Bytes) + * \endgerman + * \english + * Mask for a bit field which describes the required physical alignment + * (the required alignment is 2^x bytes) + * \endenglish + */ + CDI_MEM_ALIGN_MASK = 0x1f, + + /** + * \german + * Physische Adresse muss nicht gueltig sein + * \endgerman + * \english + * Physical address isn't required to be valid + * \endenglish + */ + CDI_MEM_VIRT_ONLY = 0x20, + + /** + * \german + * Physisch zusammenhängenden Speicher anfordern + * \endgerman + * \english + * Request physically contiguous memory + * \endenglish + */ + CDI_MEM_PHYS_CONTIGUOUS = 0x40, + + /** + * \german + * Physischen Speicher < 16 MB anfordern + * \endgerman + * \english + * Request physical memory < 16 MB + * \endenglish + */ + CDI_MEM_DMA_16M = 0x80, + + /** + * \german + * Physischen Speicher < 4 GB anfordern + * \endgerman + * \english + * Request physical memory < 4 GB + * \endenglish + */ + CDI_MEM_DMA_4G = 0x100, + + /** + * \german + * Speicher muss nicht initialisiert werden (verhindert Kopie bei + * cdi_mem_require_flags) + * \endgerman + * \english + * Memory doesn't need to be initialised (avoids copy in + * cdi_mem_require_flags) + * \endenglish + */ + CDI_MEM_NOINIT = 0x200, +} cdi_mem_flags_t; + +/** + * \german + * Beschreibt einen physischen Speicherberich (Eintrag einer + * Scatter/Gather-Liste) + * \endgerman + * \english + * Describes an area of physical memory (an entry for a scatter/gather list) + * \endenglish + */ +struct cdi_mem_sg_item { + uintptr_t start; + size_t size; +}; + +/** + * \german + * Scatter/Gather-Liste, die die physischen Adressen zu einem bestimmten + * virtuellen Speicherbereich enthält. + * \endgerman + * \english + * Scatter/Gather list which contains the physical addresses for a given area + * of virtual memory. + * \endenglish + */ +struct cdi_mem_sg_list { + size_t num; + struct cdi_mem_sg_item* items; +}; + +/** + * \german + * Beschreibt einen virtuellen Speicherbereich, je nach Flags mit einer + * Scatter/Gather-Liste der zugehörigen phyischen Adressen. + * \endgerman + * \english + * Describes an area of virtual memory, depending on the allocation flags with + * a scatter/gather list of its physical addresses. + * \endenglish + */ +struct cdi_mem_area { + size_t size; + void* vaddr; + struct cdi_mem_sg_list paddr; + + cdi_mem_osdep osdep; +}; + +/** + * \german + * Reserviert einen Speicherbereich. + * + * @param size Größe des Speicherbereichs in Bytes + * @param flags Flags, die zusätzliche Anforderungen beschreiben + * + * @return Eine cdi_mem_area bei Erfolg, NULL im Fehlerfall + * \endgerman + * \english + * Allocates a memory area. + * + * @param size Size of the memory area in bytes + * @param flags Flags that describe additional requirements + * + * @return A cdi_mem_area on success, NULL on failure + * \endenglish + */ +struct cdi_mem_area* cdi_mem_alloc(size_t size, cdi_mem_flags_t flags); + +/** + * \german + * Reserviert physisch zusammenhägenden Speicher an einer definierten Adresse + * + * @param paddr Physische Adresse des angeforderten Speicherbereichs + * @param size Größe des benötigten Speichers in Bytes + * + * @return Eine cdi_mem_area bei Erfolg, NULL im Fehlerfall + * \endgerman + * \english + * Reserves physically contiguous memory at a defined address + * + * @param paddr Physical address of the requested memory aread + * @param size Size of the requested memory area in bytes + * + * @return A cdi_mem_area on success, NULL on failure + * \endenglish + */ +struct cdi_mem_area* cdi_mem_map(uintptr_t paddr, size_t size); + +/** + * \german + * Gibt einen durch cdi_mem_alloc oder cdi_mem_map reservierten Speicherbereich + * frei + * \endgerman + * \english + * Frees a memory area that was previously allocated by cdi_mem_alloc or + * cdi_mem_map + * \endenglish + */ +void cdi_mem_free(struct cdi_mem_area* p); + +/** + * \german + * Gibt einen Speicherbereich zurück, der dieselben Daten wie @a p beschreibt, + * aber mindestens die gegebenen Flags gesetzt hat. + * + * Diese Funktion kann denselben virtuellen und physischen Speicherbereich wie + * @p benutzen oder sogar @p selbst zurückzugeben, solange der gemeinsam + * benutzte Speicher erst dann freigegeben wird, wenn sowohl @a p als auch der + * Rückgabewert durch cdi_mem_free freigegeben worden sind. + * + * Ansonsten wird ein neuer Speicherbereich reserviert und (außer wenn das + * Flag CDI_MEM_NOINIT gesetzt ist) die Daten werden aus @a p in den neu + * reservierten Speicher kopiert. + * \endgerman + * \english + * Returns a memory area that describes the same data as @a p does, but for + * which at least the given flags are set. + * + * This function may use the same virtual and physical memory areas as used in + * @a p, or it may even return @a p itself. In this case it must ensure that + * the commonly used memory is only freed when both @a p and the return value + * of this function have been freed by cdi_mem_free. + * + * Otherwise, a new memory area is allocated and data is copied from @a p into + * the newly allocated memory (unless CDI_MEM_NOINIT is set). + * \endenglish + */ +struct cdi_mem_area* cdi_mem_require_flags(struct cdi_mem_area* p, + cdi_mem_flags_t flags); + +/** + * \german + * Kopiert die Daten von @a src nach @a dest. Beide Speicherbereiche müssen + * gleich groß sein. + * + * Das bedeutet nicht unbedingt eine physische Kopie: Wenn beide + * Speicherbereiche auf denselben physischen Speicher zeigen, macht diese + * Funktion nichts. Sie kann auch andere Methoden verwenden, um den Speicher + * effektiv zu kopieren, z.B. durch geeignetes Ummappen von Pages. + * + * @return 0 bei Erfolg, -1 sonst + * \endgerman + * \english + * Copies data from @a src to @a dest. Both memory areas must be of the same + * size. + * + * This does not necessarily involve a physical copy: If both memory areas + * point to the same physical memory, this function does nothing. It can also + * use other methods to achieve the same visible effect, e.g. by remapping + * pages. + * + * @return 0 on success, -1 otherwise + * \endenglish + */ +int cdi_mem_copy(struct cdi_mem_area* dest, struct cdi_mem_area* src); + +#ifdef __cplusplus +}; // extern "C" +#endif + +#endif + -- 1.6.0.2 From kevin at tyndur.org Sat Feb 13 22:12:18 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 13 Feb 2010 22:12:18 +0100 Subject: [tyndur-devel] [PATCH 2/5] cdi: mem.h implementiert In-Reply-To: <1266095541-6084-1-git-send-email-kevin@tyndur.org> References: <1266095541-6084-1-git-send-email-kevin@tyndur.org> Message-ID: <1266095541-6084-3-git-send-email-kevin@tyndur.org> + cdi: mem.h implementiert Signed-off-by: Kevin Wolf --- src/modules/cdi/include/cdi-osdep.h | 1 + src/modules/cdi/lib/mem.c | 215 +++++++++++++++++++++++++++++++++++ 2 files changed, 216 insertions(+), 0 deletions(-) create mode 100644 src/modules/cdi/lib/mem.c diff --git a/src/modules/cdi/include/cdi-osdep.h b/src/modules/cdi/include/cdi-osdep.h index 0d052fe..204793b 100644 --- a/src/modules/cdi/include/cdi-osdep.h +++ b/src/modules/cdi/include/cdi-osdep.h @@ -77,6 +77,7 @@ typedef struct * \endenglish */ typedef struct { + int mapped; } cdi_mem_osdep; #endif diff --git a/src/modules/cdi/lib/mem.c b/src/modules/cdi/lib/mem.c new file mode 100644 index 0000000..36ad90d --- /dev/null +++ b/src/modules/cdi/lib/mem.c @@ -0,0 +1,215 @@ +/* + * Copyright (c) 2010 Kevin Wolf + * + * This program is free software. It comes without any warranty, to + * the extent permitted by applicable law. You can redistribute it + * and/or modify it under the terms of the Do What The Fuck You Want + * To Public License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/projects/COPYING.WTFPL for more details. + */ + +#include +#include +#include +#include + +#include "cdi.h" +#include "cdi/mem.h" + +/** + * \german + * Reserviert einen Speicherbereich. + * + * @param size Größe des Speicherbereichs in Bytes + * @param flags Flags, die zusätzliche Anforderungen beschreiben + * \endgerman + * \english + * Allocates a memory area. + * + * @param size Size of the memory area in bytes + * @param flags Flags that describe additional requirements + * \endenglish + */ +struct cdi_mem_area* cdi_mem_alloc(size_t size, cdi_mem_flags_t flags) +{ + dma_mem_ptr_t buffer; + struct cdi_mem_area* area; + struct cdi_mem_sg_item* sg_item; + + // Wir machen im Moment mal nur ganze Pages + if ((flags & CDI_MEM_ALIGN_MASK) > 12) { + return NULL; + } + + // Speicher holen + if (flags & CDI_MEM_VIRT_ONLY) { + buffer = mem_dma_allocate(size, 0); + } else { + buffer = mem_dma_allocate(size, 0x80); + } + + if (buffer.virt == NULL) { + return NULL; + } + + // cdi_mem_area anlegen und befuellen + sg_item = malloc(sizeof(*sg_item)); + *sg_item = (struct cdi_mem_sg_item) { + .start = (uintptr_t) buffer.phys, + .size = size, + }; + + area = malloc(sizeof(*area)); + *area = (struct cdi_mem_area) { + .size = size, + .vaddr = buffer.virt, + .paddr = { + .num = 1, + .items = sg_item, + }, + }; + + return area; +} + +/** + * Reserviert physisch zusammenhägenden Speicher an einer definierten Adresse + * + * @param paddr Physische Adresse des angeforderten Speicherbereichs + * @param size Größe des benötigten Speichers in Bytes + * + * @return Eine cdi_mem_area bei Erfolg, NULL im Fehlerfall + */ +struct cdi_mem_area* cdi_mem_map(uintptr_t paddr, size_t size) +{ + struct cdi_mem_area* area; + struct cdi_mem_sg_item* sg_item; + void* vaddr = mem_allocate_physical(size, paddr, 0); + + if (vaddr == NULL) { + return NULL; + } + + // cdi_mem_area anlegen und befuellen + sg_item = malloc(sizeof(*sg_item)); + *sg_item = (struct cdi_mem_sg_item) { + .start = paddr, + .size = size, + }; + + area = malloc(sizeof(*area)); + *area = (struct cdi_mem_area) { + .size = size, + .vaddr = vaddr, + .paddr = { + .num = 1, + .items = sg_item, + }, + .osdep = { + .mapped = 1, + }, + }; + + return area; +} + + +/** + * \german + * Gibt einen durch cdi_mem_alloc oder cdi_mem_map reservierten Speicherbereich + * frei + * \endgerman + * \english + * Frees a memory area that was previously allocated by cdi_mem_alloc or + * cdi_mem_map + * \endenglish + */ +void cdi_mem_free(struct cdi_mem_area* p) +{ + if (p->osdep.mapped) { + mem_free_physical(p->vaddr, p->size); + } else { + mem_free(p->vaddr, p->size); + } + + free(p->paddr.items); + free(p); +} + +/** + * \german + * Gibt einen Speicherbereich zurück, der dieselben Daten wie @a p beschreibt, + * aber mindestens die gegebenen Flags gesetzt hat. + * + * Diese Funktion kann denselben virtuellen und physischen Speicherbereich wie + * @p benutzen oder sogar @p selbst zurückzugeben, solange der gemeinsam + * benutzte Speicher erst dann freigegeben wird, wenn sowohl @a p als auch der + * Rückgabewert durch cdi_mem_free freigegeben worden sind. + * + * Ansonsten wird ein neuer Speicherbereich reserviert und (außer wenn das + * Flag CDI_MEM_NOINIT gesetzt ist) die Daten werden aus @a p in den neu + * reservierten Speicher kopiert. + * \endgerman + * \english + * Returns a memory area that describes the same data as @a p does, but for + * which at least the given flags are set. + * + * This function may use the same virtual and physical memory areas as used in + * @a p, or it may even return @a p itself. In this case it must ensure that + * the commonly used memory is only freed when both @a p and the return value + * of this function have been freed by cdi_mem_free. + * + * Otherwise, a new memory area is allocated and data is copied from @a p into + * the newly allocated memory (unless CDI_MEM_NOINIT is set). + * \endenglish + */ +struct cdi_mem_area* cdi_mem_require_flags(struct cdi_mem_area* p, + cdi_mem_flags_t flags) +{ + // TODO Das geht unter Umstaenden effizienter + struct cdi_mem_area* new = cdi_mem_alloc(p->size, flags); + if (new == NULL) { + return NULL; + } + + memcpy(new->vaddr, p->vaddr, new->size); + return new; +} + +/** + * \german + * Kopiert die Daten von @a src nach @a dest. Beide Speicherbereiche müssen + * gleich groß sein. + * + * Das bedeutet nicht unbedingt eine physische Kopie: Wenn beide + * Speicherbereiche auf denselben physischen Speicher zeigen, macht diese + * Funktion nichts. Sie kann auch andere Methoden verwenden, um den Speicher + * effektiv zu kopieren, z.B. durch geeignetes Ummappen von Pages. + * + * @return 0 bei Erfolg, -1 sonst + * \endgerman + * \english + * Copies data from @a src to @a dest. Both memory areas must be of the same + * size. + * + * This does not necessarily involve a physical copy: If both memory areas + * point to the same physical memory, this function does nothing. It can also + * use other methods to achieve the same visible effect, e.g. by remapping + * pages. + * + * @return 0 on success, -1 otherwise + * \endenglish + */ +int cdi_mem_copy(struct cdi_mem_area* dest, struct cdi_mem_area* src) +{ + // TODO Das geht unter Umstaenden effizienter + if (dest->size != src->size) { + return -1; + } + + if (dest->vaddr != src->vaddr) { + memcpy(dest->vaddr, src->vaddr, dest->size); + } + + return 0; +} -- 1.6.0.2 From kevin at tyndur.org Sat Feb 13 22:12:19 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 13 Feb 2010 22:12:19 +0100 Subject: [tyndur-devel] [PATCH 3/5] pcnet: Initialisierungsblock in eigene Funktion auslagern In-Reply-To: <1266095541-6084-1-git-send-email-kevin@tyndur.org> References: <1266095541-6084-1-git-send-email-kevin@tyndur.org> Message-ID: <1266095541-6084-4-git-send-email-kevin@tyndur.org> * pcnet: Der Initialisierungsblock ist etwas temporaeres und gehoert deswegen nicht in pcnet_device. Weil es aber trotzdem ein paar Zeilen Code sind, wird dieser Code in eine eigene Funktion ausgelagert, um einfacher durch cdi_mem_alloc/free ersetzbar zu werden. Signed-off-by: Kevin Wolf --- src/modules/cdi/pcnet/include/pcnet.h | 3 - src/modules/cdi/pcnet/pcnet.c | 84 +++++++++++++++++++------------- 2 files changed, 50 insertions(+), 37 deletions(-) diff --git a/src/modules/cdi/pcnet/include/pcnet.h b/src/modules/cdi/pcnet/include/pcnet.h index 000862c..6c29a56 100644 --- a/src/modules/cdi/pcnet/include/pcnet.h +++ b/src/modules/cdi/pcnet/include/pcnet.h @@ -115,9 +115,6 @@ struct pcnet_device { void *phys_receive_descriptor; void *phys_transmit_descriptor; - struct initialization_block *initialization_block; - void *phys_initialization_block; - void *receive_buffer[8]; void *transmit_buffer[8]; int last_transmit_descriptor; diff --git a/src/modules/cdi/pcnet/pcnet.c b/src/modules/cdi/pcnet/pcnet.c index a157094..e4500dc 100644 --- a/src/modules/cdi/pcnet/pcnet.c +++ b/src/modules/cdi/pcnet/pcnet.c @@ -235,11 +235,58 @@ void pcnet_stop(struct pcnet_device *netcard) { pcnet_write_csr(netcard, CSR_STATUS, STATUS_STOP); } -void pcnet_dev_init(struct pcnet_device *netcard, int promiscuous) + +static void pcnet_send_init_block(struct pcnet_device* netcard, int promisc) { struct cdi_pci_device* pci = (struct cdi_pci_device*) netcard->net.dev.bus_data; + struct initialization_block* initialization_block; + void* phys_initialization_block; + + + // Fill the initialization block + // NOTE: Transmit and receive buffer contain 8 entries + cdi_alloc_phys_mem(sizeof(struct initialization_block), + (void**) &initialization_block, + &phys_initialization_block); + memset(initialization_block, 0, sizeof(struct initialization_block)); + initialization_block->mode = promisc ? PROMISCUOUS_MODE : 0; + initialization_block->receive_length = 0x30; + initialization_block->transfer_length = 0x30; + initialization_block->receive_descriptor = + (uint32_t) netcard->phys_receive_descriptor; + initialization_block->transmit_descriptor = + (uint32_t) netcard->phys_transmit_descriptor; + initialization_block->physical_address = netcard->net.mac; + + #ifdef DEBUG + printf("pcnet: initialization block at 0x%p virtual, 0x%p physical\n", + initialization_block, + phys_initialization_block); + #endif + + // Set the address for the initialization block + pcnet_write_csr(netcard, 1, (uintptr_t) phys_initialization_block); + pcnet_write_csr(netcard, 2, (uintptr_t) phys_initialization_block >> 16); + + // TODO BCR18.BREADE / BWRITE + + // CSR0.INIT, Initialize + netcard->init_wait_for_irq = 1; + pcnet_write_csr(netcard, CSR_STATUS, + STATUS_INIT | STATUS_INTERRUPT_ENABLE); + + // Wait until initialization completed, NOTE: see pcnet_handle_interrupt() + int irq = cdi_wait_irq(pci->irq, 1000); + if(irq < 0 || netcard->init_wait_for_irq == 1) + printf("pcnet: waiting for IRQ failed: %d\n", irq); + + // FIXME Free initialization block +} + +void pcnet_dev_init(struct pcnet_device *netcard, int promiscuous) +{ // Allocate the receive & transmit descriptor buffer void *virt_desc_region; void *phys_desc_region; @@ -257,24 +304,6 @@ void pcnet_dev_init(struct pcnet_device *netcard, int promiscuous) netcard->phys_receive_descriptor = phys_desc_region; netcard->phys_transmit_descriptor = (void*) (((char*)phys_desc_region) + 2 * 1024); - // Fill the initialization block - // NOTE: Transmit and receive buffer contain 8 entries - cdi_alloc_phys_mem(sizeof(struct initialization_block), - (void**) &netcard->initialization_block, - &netcard->phys_initialization_block); - memset(netcard->initialization_block, 0, sizeof(struct initialization_block)); - netcard->initialization_block->mode = promiscuous ? PROMISCUOUS_MODE : 0; - netcard->initialization_block->receive_length = 0x30; - netcard->initialization_block->transfer_length = 0x30; - netcard->initialization_block->receive_descriptor = (uint32_t) netcard->phys_receive_descriptor; - netcard->initialization_block->transmit_descriptor = (uint32_t) netcard->phys_transmit_descriptor; - netcard->initialization_block->physical_address = netcard->net.mac; - - #ifdef DEBUG - printf("pcnet: initialization block at 0x%p virtual and 0x%p physical\n", - netcard->initialization_block, - netcard->phys_initialization_block); - #endif // Allocate the buffers memset(netcard->transmit_descriptor, 0, 2048); @@ -310,21 +339,8 @@ void pcnet_dev_init(struct pcnet_device *netcard, int promiscuous) netcard->transmit_descriptor[2 * i + 1].address = (uint32_t) phys_buffer + 2048; } - // Set the address for the initialization block - pcnet_write_csr(netcard, 1, (uintptr_t) netcard->phys_initialization_block); - pcnet_write_csr(netcard, 2, (uintptr_t) netcard->phys_initialization_block >> 16); - - // TODO BCR18.BREADE / BWRITE - - // CSR0.INIT, Initialize - netcard->init_wait_for_irq = 1; - pcnet_write_csr(netcard, CSR_STATUS, STATUS_INIT | STATUS_INTERRUPT_ENABLE); - - // Wait until initialization completed, NOTE: see pcnet_handle_interrupt() - int irq = cdi_wait_irq(pci->irq, 1000); - if(irq < 0 || netcard->init_wait_for_irq == 1) - printf("pcnet: waiting for IRQ failed: %d\n", irq); - + pcnet_send_init_block(netcard, promiscuous); + // CSR4 Enable transmit auto-padding and receive automatic padding removal // TODO DMAPLUS? uint16_t tmp = pcnet_read_csr(netcard, CSR_FEATURE); -- 1.6.0.2 From kevin at tyndur.org Sat Feb 13 22:12:20 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 13 Feb 2010 22:12:20 +0100 Subject: [tyndur-devel] [PATCH 4/5] cdi: cdi_alloc_phys_mem/addr ersetzen In-Reply-To: <1266095541-6084-1-git-send-email-kevin@tyndur.org> References: <1266095541-6084-1-git-send-email-kevin@tyndur.org> Message-ID: <1266095541-6084-5-git-send-email-kevin@tyndur.org> * cdi: In allen Treibern cdi_alloc_phys_mem durch cdi_mem_alloc ersetzen * cdi: In allen Treibern cdi_alloc_phys_addr durch cdi_mem_map ersetzen Signed-off-by: Kevin Wolf --- src/modules/cdi/ata/device.c | 16 ++++++-- src/modules/cdi/ata/device.h | 4 +- src/modules/cdi/ata/request.c | 2 +- src/modules/cdi/e1000/device.c | 19 ++++++--- src/modules/cdi/e1000/device.h | 2 +- src/modules/cdi/ne2k/include/ne2k.h | 4 +- src/modules/cdi/ne2k/ne2k.c | 13 +++++- src/modules/cdi/pcnet/pcnet.c | 61 +++++++++++++++++----------- src/modules/cdi/rtl8139/include/rtl8139.h | 4 +- src/modules/cdi/rtl8139/rtl8139.c | 13 +++++- src/modules/cdi/sis900/device.c | 15 +++++-- src/modules/cdi/sis900/device.h | 2 +- 12 files changed, 102 insertions(+), 53 deletions(-) diff --git a/src/modules/cdi/ata/device.c b/src/modules/cdi/ata/device.c index dd087c3..6e33d52 100644 --- a/src/modules/cdi/ata/device.c +++ b/src/modules/cdi/ata/device.c @@ -34,6 +34,7 @@ #include "cdi/misc.h" #include "cdi/io.h" #include "cdi/scsi.h" +#include "cdi/mem.h" #include "device.h" @@ -265,10 +266,17 @@ void ata_init_controller(struct ata_controller* controller) // Abschliessend wird noch DMA vorbereitet, wenn moeglich if (controller->port_bmr_base) { - cdi_alloc_phys_mem(sizeof(uint64_t), (void**) &controller->prdt_virt, - (void**) &controller->prdt_phys); - cdi_alloc_phys_mem(ATA_DMA_MAXSIZE, (void**) &controller->dma_buf_virt, - (void**) &controller->dma_buf_phys); + struct cdi_mem_area* buf; + + buf = cdi_mem_alloc(sizeof(uint64_t), + CDI_MEM_PHYS_CONTIGUOUS | CDI_MEM_DMA_4G); + controller->prdt_virt = buf->vaddr; + controller->prdt_phys = buf->paddr.items[0].start; + + buf = cdi_mem_alloc(ATA_DMA_MAXSIZE, + CDI_MEM_PHYS_CONTIGUOUS | CDI_MEM_DMA_4G); + controller->dma_buf_virt = buf->vaddr; + controller->dma_buf_phys = buf->paddr.items[0].start; controller->dma_use = 1; } diff --git a/src/modules/cdi/ata/device.h b/src/modules/cdi/ata/device.h index efb3f6f..6c438e0 100644 --- a/src/modules/cdi/ata/device.h +++ b/src/modules/cdi/ata/device.h @@ -367,11 +367,11 @@ struct ata_controller { /// Physische Adresse der Physical Region Descriptor Table (fuer DMA) - uint64_t* prdt_phys; + uintptr_t prdt_phys; /// Virtuelle Adresse der Physical Region Descriptor Table (fuer DMA) uint64_t* prdt_virt; /// Physische Adresse des DMA-Puffers - void* dma_buf_phys; + uintptr_t dma_buf_phys; /// Virtuelle Adresse des DMA-Puffers void* dma_buf_virt; }; diff --git a/src/modules/cdi/ata/request.c b/src/modules/cdi/ata/request.c index e98ee60..9d618c7 100644 --- a/src/modules/cdi/ata/request.c +++ b/src/modules/cdi/ata/request.c @@ -433,7 +433,7 @@ static int ata_request_dma_init(struct ata_request* request) BMR_STATUS_IRQ); // Adresse der PRDT eintragen - cdi_outl(ctrl->port_bmr_base + BMR_PRDT, (uint32_t) ctrl->prdt_phys); + cdi_outl(ctrl->port_bmr_base + BMR_PRDT, ctrl->prdt_phys); if (request->flags.direction != READ) { memcpy(ctrl->dma_buf_virt, request->buffer, size); diff --git a/src/modules/cdi/e1000/device.c b/src/modules/cdi/e1000/device.c index b21df2f..1b31987 100644 --- a/src/modules/cdi/e1000/device.c +++ b/src/modules/cdi/e1000/device.c @@ -35,6 +35,7 @@ #include "cdi.h" #include "cdi/misc.h" #include "cdi/pci.h" +#include "cdi/mem.h" #include "device.h" #include "e1000_io.h" @@ -42,7 +43,7 @@ #undef DEBUG #define PHYS(netcard, field) \ - ((uintptr_t) netcard->phys + offsetof(struct e1000_device, field)) + (netcard->phys + offsetof(struct e1000_device, field)) static void e1000_handle_interrupt(struct cdi_device* device); static uint64_t get_mac_address(struct e1000_device* device); @@ -150,16 +151,22 @@ struct cdi_device* e1000_init_device(struct cdi_bus_data* bus_data) { struct cdi_pci_device* pci = (struct cdi_pci_device*) bus_data; struct e1000_device* netcard; - void* phys_device; + struct cdi_mem_area* buf; if (!((pci->vendor_id == 0x8086) && (pci->device_id == 0x100e))) { return NULL; } - cdi_alloc_phys_mem(sizeof(*netcard), (void**) &netcard, &phys_device); + buf = cdi_mem_alloc(sizeof(*netcard), + CDI_MEM_PHYS_CONTIGUOUS | CDI_MEM_DMA_4G | 2); + if (buf == NULL) { + return NULL; + } + + netcard = buf->vaddr; memset(netcard, 0, sizeof(*netcard)); - netcard->phys = phys_device; + netcard->phys = buf->paddr.items[0].start; netcard->net.dev.bus_data = (struct cdi_bus_data*) pci; // PCI-bezogenes Zeug initialisieren @@ -172,8 +179,8 @@ struct cdi_device* e1000_init_device(struct cdi_bus_data* bus_data) int i; for (i = 0; (res = cdi_list_get(reslist, i)); i++) { if (res->type == CDI_PCI_MEMORY) { - netcard->mem_base = - cdi_alloc_phys_addr(res->length, res->start); + struct cdi_mem_area* mmio = cdi_mem_map(res->start, res->length); + netcard->mem_base = mmio->vaddr; } } diff --git a/src/modules/cdi/e1000/device.h b/src/modules/cdi/e1000/device.h index 9266e0f..2a10365 100644 --- a/src/modules/cdi/e1000/device.h +++ b/src/modules/cdi/e1000/device.h @@ -143,7 +143,7 @@ struct e1000_rx_descriptor { struct e1000_device { struct cdi_net_device net; - void* phys; + uintptr_t phys; struct e1000_tx_descriptor tx_desc[TX_BUFFER_NUM]; uint8_t tx_buffer[TX_BUFFER_NUM * TX_BUFFER_SIZE]; diff --git a/src/modules/cdi/ne2k/include/ne2k.h b/src/modules/cdi/ne2k/include/ne2k.h index 585eab5..0102ce8 100644 --- a/src/modules/cdi/ne2k/include/ne2k.h +++ b/src/modules/cdi/ne2k/include/ne2k.h @@ -71,7 +71,7 @@ #define NE_DATA 0x10 #define PHYS(netcard, field) \ - ((uintptr_t) netcard->phys + offsetof(struct rtl8139_device, field)) + (netcard->phys + offsetof(struct rtl8139_device, field)) #define RX_BUFFER_SIZE 0x2000 #define TX_BUFFER_SIZE 0x1000 @@ -84,7 +84,7 @@ typedef struct { struct ne2k_device { struct cdi_net_device net; - void* phys; + uintptr_t phys; uint16_t port_base; uint8_t next_packet; diff --git a/src/modules/cdi/ne2k/ne2k.c b/src/modules/cdi/ne2k/ne2k.c index 7f1262e..d3fa019 100644 --- a/src/modules/cdi/ne2k/ne2k.c +++ b/src/modules/cdi/ne2k/ne2k.c @@ -35,6 +35,7 @@ #include "cdi/pci.h" #include "cdi/io.h" #include "cdi/misc.h" +#include "cdi/mem.h" #include "ne2k.h" #include "ethernet.h" @@ -81,16 +82,22 @@ struct cdi_device* ne2k_init_device(struct cdi_bus_data* bus_data) { struct cdi_pci_device* pci = (struct cdi_pci_device*) bus_data; struct ne2k_device* netcard; - void* phys_device; + struct cdi_mem_area* buf; if (!((pci->vendor_id == 0x10ec) && (pci->device_id == 0x8029))) { return NULL; } - cdi_alloc_phys_mem(sizeof(*netcard), (void**) &netcard, &phys_device); + buf = cdi_mem_alloc(sizeof(*netcard), + CDI_MEM_PHYS_CONTIGUOUS | CDI_MEM_DMA_4G | 2); + if (buf == NULL) { + return NULL; + } + + netcard = buf->vaddr; memset(netcard, 0, sizeof(*netcard)); - netcard->phys = phys_device; + netcard->phys = buf->paddr.items[0].start; netcard->net.dev.bus_data = (struct cdi_bus_data*) pci; // PCI-bezogenes Zeug initialisieren diff --git a/src/modules/cdi/pcnet/pcnet.c b/src/modules/cdi/pcnet/pcnet.c index e4500dc..ea0b4d7 100644 --- a/src/modules/cdi/pcnet/pcnet.c +++ b/src/modules/cdi/pcnet/pcnet.c @@ -28,6 +28,7 @@ #include "pcnet.h" #include "cdi/io.h" +#include "cdi/mem.h" #include #include @@ -242,14 +243,14 @@ static void pcnet_send_init_block(struct pcnet_device* netcard, int promisc) (struct cdi_pci_device*) netcard->net.dev.bus_data; struct initialization_block* initialization_block; - void* phys_initialization_block; - + struct cdi_mem_area* buf; // Fill the initialization block // NOTE: Transmit and receive buffer contain 8 entries - cdi_alloc_phys_mem(sizeof(struct initialization_block), - (void**) &initialization_block, - &phys_initialization_block); + buf = cdi_mem_alloc(sizeof(struct initialization_block), + CDI_MEM_DMA_4G | CDI_MEM_PHYS_CONTIGUOUS); + + initialization_block = buf->vaddr; memset(initialization_block, 0, sizeof(struct initialization_block)); initialization_block->mode = promisc ? PROMISCUOUS_MODE : 0; initialization_block->receive_length = 0x30; @@ -263,12 +264,12 @@ static void pcnet_send_init_block(struct pcnet_device* netcard, int promisc) #ifdef DEBUG printf("pcnet: initialization block at 0x%p virtual, 0x%p physical\n", initialization_block, - phys_initialization_block); + (void*) buf->paddr.items[0].start); #endif // Set the address for the initialization block - pcnet_write_csr(netcard, 1, (uintptr_t) phys_initialization_block); - pcnet_write_csr(netcard, 2, (uintptr_t) phys_initialization_block >> 16); + pcnet_write_csr(netcard, 1, buf->paddr.items[0].start); + pcnet_write_csr(netcard, 2, buf->paddr.items[0].start >> 16); // TODO BCR18.BREADE / BWRITE @@ -282,41 +283,50 @@ static void pcnet_send_init_block(struct pcnet_device* netcard, int promisc) if(irq < 0 || netcard->init_wait_for_irq == 1) printf("pcnet: waiting for IRQ failed: %d\n", irq); - // FIXME Free initialization block + // Free initialization block + cdi_mem_free(buf); } void pcnet_dev_init(struct pcnet_device *netcard, int promiscuous) { // Allocate the receive & transmit descriptor buffer - void *virt_desc_region; - void *phys_desc_region; - if (cdi_alloc_phys_mem(4096, &virt_desc_region, &phys_desc_region) == -1) - { + struct cdi_mem_area* desc; + + desc = cdi_mem_alloc(4096, CDI_MEM_DMA_4G | CDI_MEM_PHYS_CONTIGUOUS); + if (desc == NULL) { printf("pcnet: failed to allocate descriptor region\n"); return; } #ifdef DEBUG - printf("pcnet: descriptor region at 0x%p virtual and 0x%p physical\n", virt_desc_region, phys_desc_region); + printf("pcnet: descriptor region at 0x%p virtual and 0x%p physical\n", + desc->vaddr, (void*) desc->paddr.items[0].start); #endif - netcard->receive_descriptor = virt_desc_region; - netcard->transmit_descriptor = (struct transmit_descriptor*) (((char*)virt_desc_region) + 2 * 1024); - netcard->phys_receive_descriptor = phys_desc_region; - netcard->phys_transmit_descriptor = (void*) (((char*)phys_desc_region) + 2 * 1024); + netcard->receive_descriptor = desc->vaddr; + netcard->transmit_descriptor = (struct transmit_descriptor*) + ((char*) desc->vaddr + 2 * 1024); + netcard->phys_receive_descriptor = (void*) desc->paddr.items[0].start; + netcard->phys_transmit_descriptor = (void*) + ((desc->paddr.items[0].start) + 2 * 1024); // Allocate the buffers memset(netcard->transmit_descriptor, 0, 2048); - void *virt_buffer; - void *phys_buffer; int i = 0; for (;i < 4;i++) { - if (cdi_alloc_phys_mem(4096, &virt_buffer, &phys_buffer) == -1) - { + void* virt_buffer; + uintptr_t phys_buffer; + struct cdi_mem_area* buf; + + buf = cdi_mem_alloc(4096, CDI_MEM_DMA_4G | CDI_MEM_PHYS_CONTIGUOUS); + if (buf == 0) { DEBUG_MSG("cdi_alloc_phys_mem failed"); return; } + virt_buffer = buf->vaddr; + phys_buffer = buf->paddr.items[0].start; + netcard->receive_buffer[2 * i] = virt_buffer; netcard->receive_buffer[2 * i + 1] = ((char*)virt_buffer) + 2048; netcard->receive_descriptor[2 * i].address = (uint32_t) phys_buffer; @@ -328,11 +338,14 @@ void pcnet_dev_init(struct pcnet_device *netcard, int promiscuous) netcard->receive_descriptor[2 * i + 1].flags2 = 0; netcard->receive_descriptor[2 * i + 1].res = 0; - if (cdi_alloc_phys_mem(4096, &virt_buffer, &phys_buffer) == -1) - { + buf = cdi_mem_alloc(4096, CDI_MEM_DMA_4G | CDI_MEM_PHYS_CONTIGUOUS); + if (buf == 0) { DEBUG_MSG("cdi_alloc_phys_mem failed"); return; } + virt_buffer = buf->vaddr; + phys_buffer = buf->paddr.items[0].start; + netcard->transmit_buffer[2 * i] = virt_buffer; netcard->transmit_buffer[2 * i + 1] = ((char*)virt_buffer) + 2048; netcard->transmit_descriptor[2 * i].address = (uint32_t) phys_buffer; diff --git a/src/modules/cdi/rtl8139/include/rtl8139.h b/src/modules/cdi/rtl8139/include/rtl8139.h index 3ec81b0..aafa71f 100644 --- a/src/modules/cdi/rtl8139/include/rtl8139.h +++ b/src/modules/cdi/rtl8139/include/rtl8139.h @@ -70,7 +70,7 @@ #define ISR_RECEIVE_OK (1 << 0) #define PHYS(netcard, field) \ - ((uintptr_t) netcard->phys + offsetof(struct rtl8139_device, field)) + (netcard->phys + offsetof(struct rtl8139_device, field)) #define RX_BUFFER_SIZE 0x2000 #define TX_BUFFER_SIZE 0x1000 @@ -83,7 +83,7 @@ typedef struct { struct rtl8139_device { struct cdi_net_device net; - void* phys; + uintptr_t phys; uint16_t port_base; uint8_t buffer[TX_BUFFER_SIZE] diff --git a/src/modules/cdi/rtl8139/rtl8139.c b/src/modules/cdi/rtl8139/rtl8139.c index 600f3e9..6571c56 100644 --- a/src/modules/cdi/rtl8139/rtl8139.c +++ b/src/modules/cdi/rtl8139/rtl8139.c @@ -35,6 +35,7 @@ #include "cdi/pci.h" #include "cdi/io.h" #include "cdi/misc.h" +#include "cdi/mem.h" #include "rtl8139.h" #include "ethernet.h" @@ -79,16 +80,22 @@ struct cdi_device* rtl8139_init_device(struct cdi_bus_data* bus_data) { struct cdi_pci_device* pci = (struct cdi_pci_device*) bus_data; struct rtl8139_device* netcard; - void* phys_device; + struct cdi_mem_area* buf; if (!((pci->vendor_id == 0x10ec) && (pci->device_id == 0x8139))) { return NULL; } - cdi_alloc_phys_mem(sizeof(*netcard), (void**) &netcard, &phys_device); + buf = cdi_mem_alloc(sizeof(*netcard), + CDI_MEM_PHYS_CONTIGUOUS | CDI_MEM_DMA_4G | 2); + if (buf == NULL) { + return NULL; + } + + netcard = buf->vaddr; memset(netcard, 0, sizeof(*netcard)); - netcard->phys = phys_device; + netcard->phys = buf->paddr.items[0].start; netcard->net.dev.bus_data = (struct cdi_bus_data*) pci; // PCI-bezogenes Zeug initialisieren diff --git a/src/modules/cdi/sis900/device.c b/src/modules/cdi/sis900/device.c index 30c6d39..aa5d7c8 100644 --- a/src/modules/cdi/sis900/device.c +++ b/src/modules/cdi/sis900/device.c @@ -34,6 +34,7 @@ #include "cdi.h" #include "cdi/misc.h" +#include "cdi/mem.h" #include "device.h" #include "sis900_io.h" @@ -46,7 +47,7 @@ #undef DEBUG #define PHYS(netcard, field) \ - ((uintptr_t) netcard->phys + offsetof(struct sis900_device, field)) + (netcard->phys + offsetof(struct sis900_device, field)) static void sis900_handle_interrupt(struct cdi_device* device); @@ -185,16 +186,22 @@ struct cdi_device* sis900_init_device(struct cdi_bus_data* bus_data) { struct cdi_pci_device* pci = (struct cdi_pci_device*) bus_data; struct sis900_device* netcard; - void* phys_device; + struct cdi_mem_area* buf; if (!((pci->vendor_id == 0x1039) && (pci->device_id == 0x0900))) { return NULL; } - cdi_alloc_phys_mem(sizeof(*netcard), (void**) &netcard, &phys_device); + buf = cdi_mem_alloc(sizeof(*netcard), + CDI_MEM_PHYS_CONTIGUOUS | CDI_MEM_DMA_4G | 2); + if (buf == NULL) { + return NULL; + } + + netcard = buf->vaddr; memset(netcard, 0, sizeof(*netcard)); - netcard->phys = phys_device; + netcard->phys = buf->paddr.items[0].start; netcard->net.dev.bus_data = (struct cdi_bus_data*) pci; // PCI-bezogenes Zeug initialisieren diff --git a/src/modules/cdi/sis900/device.h b/src/modules/cdi/sis900/device.h index cd110c0..7698d2f 100644 --- a/src/modules/cdi/sis900/device.h +++ b/src/modules/cdi/sis900/device.h @@ -129,7 +129,7 @@ struct sis900_tx_descriptor { struct sis900_device { struct cdi_net_device net; - void* phys; + uintptr_t phys; struct sis900_tx_descriptor tx_desc[TX_BUFFER_NUM]; uint8_t tx_buffer[TX_BUFFER_NUM * TX_BUFFER_SIZE]; -- 1.6.0.2 From kevin at tyndur.org Sat Feb 13 22:12:21 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 13 Feb 2010 22:12:21 +0100 Subject: [tyndur-devel] [PATCH 5/5] cdi: Veraltete Funktionen entfernt In-Reply-To: <1266095541-6084-1-git-send-email-kevin@tyndur.org> References: <1266095541-6084-1-git-send-email-kevin@tyndur.org> Message-ID: <1266095541-6084-6-git-send-email-kevin@tyndur.org> - cdi: Speicherverwaltungsfunktionen aus misc.h entfernt Signed-off-by: Kevin Wolf --- src/modules/cdi/include/cdi/misc.h | 23 --------------------- src/modules/cdi/lib/misc.c | 39 ------------------------------------ 2 files changed, 0 insertions(+), 62 deletions(-) diff --git a/src/modules/cdi/include/cdi/misc.h b/src/modules/cdi/include/cdi/misc.h index 2049c62..229f6ff 100644 --- a/src/modules/cdi/include/cdi/misc.h +++ b/src/modules/cdi/include/cdi/misc.h @@ -52,29 +52,6 @@ int cdi_reset_wait_irq(uint8_t irq); int cdi_wait_irq(uint8_t irq, uint32_t timeout); /** - * Reserviert physisch zusammenhaengenden Speicher. - * - * @param size Groesse des benoetigten Speichers in Bytes - * @param vaddr Pointer, in den die virtuelle Adresse des reservierten - * Speichers geschrieben wird. - * @param paddr Pointer, in den die physische Adresse des reservierten - * Speichers geschrieben wird. - * - * @return 0 wenn der Speicher erfolgreich reserviert wurde, -1 sonst - */ -int cdi_alloc_phys_mem(size_t size, void** vaddr, void** paddr); - -/** - * Reserviert physisch zusammenhaengenden Speicher an einer definierten Adresse. - * - * @param size Groesse des benoetigten Speichers in Bytes - * @param paddr Physikalische Adresse des angeforderten Speicherbereichs - * - * @return Virtuelle Adresse, wenn Speicher reserviert wurde, sonst 0 - */ -void* cdi_alloc_phys_addr(size_t size, uintptr_t paddr); - -/** * Reserviert IO-Ports * * @return 0 wenn die Ports erfolgreich reserviert wurden, -1 sonst. diff --git a/src/modules/cdi/lib/misc.c b/src/modules/cdi/lib/misc.c index 4abd03f..11661b4 100644 --- a/src/modules/cdi/lib/misc.c +++ b/src/modules/cdi/lib/misc.c @@ -145,45 +145,6 @@ int cdi_wait_irq(uint8_t irq, uint32_t timeout) return 0; } - -/** - * Reserviert physisch zusammenhaengenden Speicher. - * - * @param size Groesse des benoetigten Speichers in Bytes - * @param vaddr Pointer, in den die virtuelle Adresse des reservierten - * Speichers geschrieben wird. - * @param paddr Pointer, in den die physische Adresse des reservierten - * Speichers geschrieben wird. - * - * @return 0 wenn der Speicher erfolgreich reserviert wurde, -1 sonst - */ -int cdi_alloc_phys_mem(size_t size, void** vaddr, void** paddr) -{ - dma_mem_ptr_t buffer = mem_dma_allocate(size, 0x80); - - if (buffer.virt == NULL) { - return -1; - } - - *vaddr = buffer.virt; - *paddr = buffer.phys; - - return 0; -} - -/** - * Reserviert physisch zusammenhaengenden Speicher an einer definierten Adresse. - * - * @param size Groesse des benoetigten Speichers in Bytes - * @param paddr Physikalische Adresse des angeforderten Speicherbereichs - * - * @return Virtuelle Adresse, wenn Speicher reserviert wurde, sonst 0 - */ -void* cdi_alloc_phys_addr(size_t size, uintptr_t paddr) -{ - return mem_allocate_physical(size, paddr, 0); -} - /** * Reserviert IO-Ports * -- 1.6.0.2