From kevin at tyndur.org Tue Feb 2 22:37:20 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Tue, 2 Feb 2010 22:37:20 +0100 Subject: [cdi-devel] CDI status Message-ID: <20100202213718.GA2370@silvanus> Hi all, I'm under impression that we have accumulated so many points that need work that it's easy to lose the big picture. What I'm trying with this mail is to summarize them, gather their current status and maybe throughout this thread turn some abstract things into concrete items that can be hacked on. First of all, we should decide what the first release of CDI should look like - in terms of work done and also regarding the release date. Two or three weeks ago I had a conversation with Matt about this and we thought that end of February would be a reasonable goal. However, since then we've had only little activity, so if we want it to happen, we'll need to start moving really soon. For the other part, I'll just write down the items that I have in mind. Feel free to add any items I missed. Also, if you want to take an item maybe you could tell us what your plans looks like. I hope for each item there is someone who feels responsible - if not, there's something wrong. And of course you may correct my estimations of the status and/or importance of a feature. * mem.h: I think the general approach has been agreed on, we just need to do the details (most important: find a better name for cdi_mem_quok_area!) I hope to get it done this week, so I can convert drivers to it on the weekend. Critical for the release. * Automatic Driver Loader: Agreement on the mechanism, patches are still missing. Important for the release. * Inter-Driver Communication (IDC): As I understand it, this blocks USB and audio. I'd really like to have it in the release, but I'm not sure if we can do it in time. * Asynchronous interfaces for block and network: No decision yet. We need a decision for the release as this changes existing interfaces heavily. * Logging functions: No concrete suggestions yet * USB support: Drivers exist for UHCI, OHCI and USB mass storage. They are missing CDI infrastructure (IDC) to work in a clean way. Might need a rewrite or major refactoring according to Max. I tend to say it would be nice to have, but not a show stopper. What is Pedigree's policy regarding USB? Only native drivers? Or maybe Max and Eddy could get together and create a nice design that would replace existing drivers? * Audio support: Lacks a good interface, implementation blocked by IDC. I'd consider it optional for the release. * Video support: Not much aoctivity recently. Optional. * Network drivers: 3c90x, tulip yet to implement. Making pcnet and e1000 usable on real hardware wouldn't be bad either. It's a nice list for only four weekends, so I'm not sure how much of it we can really do. Probably I also forgot some items that should be considered. I'm curious what you think about all this. Kevin From kevin at tyndur.org Tue Feb 2 23:11:27 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Tue, 2 Feb 2010 23:11:27 +0100 Subject: [cdi-devel] CDI status In-Reply-To: <20100202213718.GA2370@silvanus> References: <20100202213718.GA2370@silvanus> Message-ID: <20100202221126.GB2370@silvanus> On Tue, Feb 02, 2010 at 10:37:20PM +0100, Kevin Wolf wrote: > Hi all, > > I'm under impression that we have accumulated so many points that need > work that it's easy to lose the big picture. What I'm trying with this > mail is to summarize them, gather their current status and maybe > throughout this thread turn some abstract things into concrete items > that can be hacked on. > > First of all, we should decide what the first release of CDI should look > like - in terms of work done and also regarding the release date. Two or > three weeks ago I had a conversation with Matt about this and we thought > that end of February would be a reasonable goal. However, since then > we've had only little activity, so if we want it to happen, we'll need > to start moving really soon. > > For the other part, I'll just write down the items that I have in mind. > Feel free to add any items I missed. Also, if you want to take an item > maybe you could tell us what your plans looks like. I hope for each item > there is someone who feels responsible - if not, there's something > wrong. And of course you may correct my estimations of the status and/or > importance of a feature. > > * mem.h: I think the general approach has been agreed on, we just need > to do the details (most important: find a better name for > cdi_mem_quok_area!) I hope to get it done this week, so I can convert > drivers to it on the weekend. Critical for the release. > > * Automatic Driver Loader: Agreement on the mechanism, patches are > still missing. Important for the release. > > * Inter-Driver Communication (IDC): As I understand it, this blocks USB > and audio. I'd really like to have it in the release, but I'm not sure > if we can do it in time. > > * Asynchronous interfaces for block and network: No decision yet. We > need a decision for the release as this changes existing interfaces > heavily. > > * Logging functions: No concrete suggestions yet > > * USB support: Drivers exist for UHCI, OHCI and USB mass storage. They > are missing CDI infrastructure (IDC) to work in a clean way. Might > need a rewrite or major refactoring according to Max. I tend to say it > would be nice to have, but not a show stopper. > > What is Pedigree's policy regarding USB? Only native drivers? Or maybe > Max and Eddy could get together and create a nice design that would > replace existing drivers? > > * Audio support: Lacks a good interface, implementation blocked by IDC. > I'd consider it optional for the release. > > * Video support: Not much aoctivity recently. Optional. > > * Network drivers: 3c90x, tulip yet to implement. Making pcnet and e1000 > usable on real hardware wouldn't be bad either. Whoops, forgot the most important ones, the documentation: * Translate existing headers * Write an overview with general information for each module * Write some kind of tutorials for driver implementers and CDI implementers > > It's a nice list for only four weekends, so I'm not sure how much of it > we can really do. Probably I also forgot some items that should be > considered. > > I'm curious what you think about all this. > > Kevin > _______________________________________________ > cdi-devel mailing list > cdi-devel at tyndur.org > http://list.tyndur.org/cgi-bin/mailman/listinfo/cdi-devel From matthew at theiselins.net Wed Feb 3 04:16:05 2010 From: matthew at theiselins.net (Matthew Iselin) Date: Wed, 3 Feb 2010 13:16:05 +1000 Subject: [cdi-devel] CDI status In-Reply-To: <20100202213718.GA2370@silvanus> References: <20100202213718.GA2370@silvanus> Message-ID: On Wed, Feb 3, 2010 at 7:37 AM, Kevin Wolf wrote: > First of all, we should decide what the first release of CDI should look > like - in terms of work done and also regarding the release date. Two or > three weeks ago I had a conversation with Matt about this and we thought > that end of February would be a reasonable goal. However, since then > we've had only little activity, so if we want it to happen, we'll need > to start moving really soon. Completely agree. > * mem.h: I think the general approach has been agreed on, we just need > ?to do the details (most important: find a better name for > ?cdi_mem_quok_area!) I hope to get it done this week, so I can convert > ?drivers to it on the weekend. Critical for the release. cdi_mem_change_buffer_semantics? It's certainly not an easy function to name, especially since its behaviour is hard to explain in a few words. > * Automatic Driver Loader: Agreement on the mechanism, patches are > ?still missing. Important for the release. I might be able to put together some patches this week. Should I look at making this a priority, in order to get this happening relatively soon? > * Inter-Driver Communication (IDC): As I understand it, this blocks USB > ?and audio. I'd really like to have it in the release, but I'm not sure > ?if we can do it in time. We'll see how we go here. There's nothing that I know of blocking it from being implemented, but implementation and testing might take a while... > * Asynchronous interfaces for block and network: No decision yet. We > ?need a decision for the release as this changes existing interfaces > ?heavily. I'd like to hear thoughts from Max and Rich with respect to where we are at right now with this discussion. This is probably, in my opinion, the most important CDI design step so far as it will affect the interface significantly (as you said). The last thing we want to do is change the interface post-first-release. > * Logging functions: No concrete suggestions yet I didn't even know logging functions had come up in discussion ;) > * USB support: Drivers exist for UHCI, OHCI and USB mass storage. They > ?are missing CDI infrastructure (IDC) to work in a clean way. Might > ?need a rewrite or major refactoring according to Max. I tend to say it > ?would be nice to have, but not a show stopper. Depends on IDC, so we'll see where we get to here. > ?What is Pedigree's policy regarding USB? Only native drivers? Or maybe > ?Max and Eddy could get together and create a nice design that would > ?replace existing drivers? I don't really mind. Perhaps Max should join #pedigree on Freenode and have a chat to Eduard about combining forces to develop UHCI, OHCI and EHCI CDI drivers. I know Eduard has implemented a HID driver, to an extent, for Pedigree - maybe this could help too? > * Audio support: Lacks a good interface, implementation blocked by IDC. > ?I'd consider it optional for the release. Optional - nice to have, but if it's still not around at release time, forget about it for now. > * Video support: Not much aoctivity recently. Optional. I think video needs some serious design discussion before it comes close to being ready for implementation. I wouldn't be surprised if it isn't included in the release. > * Network drivers: 3c90x, tulip yet to implement. Making pcnet and e1000 > ?usable on real hardware wouldn't be bad either. Hmm, I can probably port my 3c90x driver to CDI (but I'm really time-poor at the moment). Getting pcnet and e1000 working on real hardware should be a high priority though. It's hard to justify using a driver interface when the drivers don't work outside of an emulator :) > It's a nice list for only four weekends, so I'm not sure how much of it > we can really do. Probably I also forgot some items that should be > considered. Of those that you did.... > * Translate existing headers Rich seems to be doing a good job with this so far. I'd contribute but I'd be using Google Translator ;) > * Write an overview with general information for each module Sounds like fun. Which modules still need this done? > * Write some kind of tutorials for driver implementers and CDI > implementers We need to find a small piece of useful hardware that's easy to program for that we can pick apart and write a tutorial for. That way the tutorial is practical and has a positive outcome as well. Cheers, Matt From alex at tyndur.org Thu Feb 4 16:59:51 2010 From: alex at tyndur.org (Alexander Siol) Date: Thu, 04 Feb 2010 16:59:51 +0100 Subject: [cdi-devel] CDI status In-Reply-To: References: <20100202213718.GA2370@silvanus> Message-ID: <20100204165951.197810la46buml87@mail.famkaufmann.info> On Wed, Feb 03, 2010 at 01:16:05PM +1000, Matthew Iselin wrote: > On Wed, Feb 3, 2010 at 7:37 AM, Kevin Wolf wrote: > > First of all, we should decide what the first release of CDI should look > > like - in terms of work done and also regarding the release date. Two or > > three weeks ago I had a conversation with Matt about this and we thought > > that end of February would be a reasonable goal. However, since then > > we've had only little activity, so if we want it to happen, we'll need > > to start moving really soon. > > Completely agree. I'm not certain if end of february would be a good goal here - that's just a bit to soon, in my opinion. But getting a stable release out soon should be a primary goal. > > * Automatic Driver Loader: Agreement on the mechanism, patches are > > ?still missing. Important for the release. > > I might be able to put together some patches this week. Should I look > at making this a priority, in order to get this happening relatively > soon? > I think this should really be done before a release - especially Hotplugging would be great to have, considering USB. > > * Asynchronous interfaces for block and network: No decision yet. We > > ?need a decision for the release as this changes existing interfaces > > ?heavily. > > I'd like to hear thoughts from Max and Rich with respect to where we > are at right now with this discussion. This is probably, in my > opinion, the most important CDI design step so far as it will affect > the interface significantly (as you said). The last thing we want to > do is change the interface post-first-release. > There's really no need to _change_ the whole interface to add support for this. Just add functions for asynchronous access, the old synchronous ones could then be implemented on top of those (ok, doing this at driver level really cannot to be considered a nice solution, but I think it's acceptable for a time at least). > > * Logging functions: No concrete suggestions yet > > I didn't even know logging functions had come up in discussion ;) > Never heard of those ideas, either. I wouldn't consider this important. > > * USB support: Drivers exist for UHCI, OHCI and USB mass storage. They > > ?are missing CDI infrastructure (IDC) to work in a clean way. Might > > ?need a rewrite or major refactoring according to Max. I tend to say it > > ?would be nice to have, but not a show stopper. > > Depends on IDC, so we'll see where we get to here. > Would definitive be nice to have. If it's doable in a reasonable amount of time, implement it. Otherwise, really shouldn't be a show stopper. > > * Audio support: Lacks a good interface, implementation blocked by IDC. > > ?I'd consider it optional for the release. > > Optional - nice to have, but if it's still not around at release time, > forget about it for now. Totally agree. > > > * Video support: Not much aoctivity recently. Optional. > > I think video needs some serious design discussion before it comes > close to being ready for implementation. I wouldn't be surprised if it > isn't included in the release. Sorry for the lack of activity. I've got a working "prototype" in development, which _should_ be suitable for most 2d-accelerated applications. But making it a necessarity is definitive out of question - testing needs to be done, there are neither drivers working on real hardware atm (don't ask me why the VBE modeset fails on my hardware, I've got no idea), nor drivers for real hardware (only software rendering - which is quite slow) . On top of that, video requires a lot of code on the OS side (for interface and the like). So, let's just keep this out of the release for now. > > > * Network drivers: 3c90x, tulip yet to implement. Making pcnet and e1000 > > ?usable on real hardware wouldn't be bad either. > > Hmm, I can probably port my 3c90x driver to CDI (but I'm really > time-poor at the moment). Getting pcnet and e1000 working on real > hardware should be a high priority though. It's hard to justify using > a driver interface when the drivers don't work outside of an emulator > :) I could try to get the 3c90x working, or at least help testing (3c905c). But I've really no idea if I'm going to have the time to do that until end of February - pre-exams for my Abitur are just around the corner ;) > > * Write some kind of tutorials for driver implementers and CDI > > implementers > > We need to find a small piece of useful hardware that's easy to > program for that we can pick apart and write a tutorial for. That way > the tutorial is practical and has a positive outcome as well. I'm not quite sure, but as far as I understand it, this is going to have to wait until the driver loading stuff is done (hardware probing _is_ moving, isn't it?) - so there's no point in writing tutorials now. For the small piece of useful hardware, how about using the 3c90x? Since that driver need's to be done anyway, I'd consider writing about that development pretty straightforward. Alex From matthew at theiselins.net Thu Feb 4 21:53:15 2010 From: matthew at theiselins.net (Matthew Iselin) Date: Fri, 5 Feb 2010 06:53:15 +1000 Subject: [cdi-devel] CDI status In-Reply-To: <20100204165951.197810la46buml87@mail.famkaufmann.info> References: <20100202213718.GA2370@silvanus> <20100204165951.197810la46buml87@mail.famkaufmann.info> Message-ID: On Fri, Feb 5, 2010 at 1:59 AM, Alexander Siol wrote: >> > * Write some kind of tutorials for driver implementers and CDI >> > ?implementers >> >> We need to find a small piece of useful hardware that's easy to >> program for that we can pick apart and write a tutorial for. That way >> the tutorial is practical and has a positive outcome as well. > > I'm not quite sure, but as far as I understand it, this is going to have to > wait until the driver loading stuff is done (hardware probing _is_ moving, > isn't it?) - so there's no point in writing tutorials now. > For the small piece of useful hardware, how about using the 3c90x? > Since that driver need's to be done anyway, I'd consider writing about that > development pretty straightforward. I was thinking that or the ne2k. Probably the 3c90x in thinking about it, as it would cover more of the interface initially (memory for descriptors, port I/O, etc...). Cheers, Matt From kevin at tyndur.org Fri Feb 5 00:18:33 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Fri, 5 Feb 2010 00:18:33 +0100 Subject: [cdi-devel] CDI status In-Reply-To: References: <20100202213718.GA2370@silvanus> Message-ID: <20100204231832.GA17930@silvanus> On Wed, Feb 03, 2010 at 01:16:05PM +1000, Matthew Iselin wrote: > On Wed, Feb 3, 2010 at 7:37 AM, Kevin Wolf wrote: > > * mem.h: I think the general approach has been agreed on, we just need > > ?to do the details (most important: find a better name for > > ?cdi_mem_quok_area!) I hope to get it done this week, so I can convert > > ?drivers to it on the weekend. Critical for the release. > > cdi_mem_change_buffer_semantics? It's certainly not an easy function > to name, especially since its behaviour is hard to explain in a few > words. change_buffer_semantics sounds like an existing buffer is modified, not a new instance is returned. Also, what does semantics mean for a buffer? I'd likely think of the actual data there. > > > * Automatic Driver Loader: Agreement on the mechanism, patches are > > ?still missing. Important for the release. > > I might be able to put together some patches this week. Should I look > at making this a priority, in order to get this happening relatively > soon? It's a central part of infrastructure (even more so if you take the cdi_provide_device as a part of it), so I'd say yes. Although this doesn't mean that other parts are much less important. > > * Inter-Driver Communication (IDC): As I understand it, this blocks USB > > ?and audio. I'd really like to have it in the release, but I'm not sure > > ?if we can do it in time. > > We'll see how we go here. There's nothing that I know of blocking it > from being implemented, but implementation and testing might take a > while... Well, before implementing it I guess we should start with an interface. ;-) > > * Asynchronous interfaces for block and network: No decision yet. We > > ?need a decision for the release as this changes existing interfaces > > ?heavily. > > I'd like to hear thoughts from Max and Rich with respect to where we > are at right now with this discussion. This is probably, in my > opinion, the most important CDI design step so far as it will affect > the interface significantly (as you said). The last thing we want to > do is change the interface post-first-release. Rich? Max? I'm not really hesitant to change interfaces later on if it turns out to be helpful. Being able to change interfaces as need arises is one of our strengths. And this means that a solution as suggested by Alex (leave old functions around and add new asynchronous ones) doesn't work for me. If we get a better interface the old one must die. That said, getting it right in the release should be our goal. > > * Logging functions: No concrete suggestions yet > > I didn't even know logging functions had come up in discussion ;) They came up long ago, but my todo list doesn't forget anything. ;-) > > * Network drivers: 3c90x, tulip yet to implement. Making pcnet and e1000 > > ?usable on real hardware wouldn't be bad either. > > Hmm, I can probably port my 3c90x driver to CDI (but I'm really > time-poor at the moment). Getting pcnet and e1000 working on real > hardware should be a high priority though. It's hard to justify using > a driver interface when the drivers don't work outside of an emulator > :) Who has an e1000 or a pcnet in real hardware? I know that Toni has an e1000, so that's probably a job for him. No idea about pcnet. > > * Write an overview with general information for each module > > Sounds like fun. Which modules still need this done? Everything but core. Kevin From kevin at tyndur.org Sat Feb 6 17:05:40 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 6 Feb 2010 17:05:40 +0100 Subject: [cdi-devel] [PATCH v2] mem.h: Handling memory areas Message-ID: <1265472340-31626-1-git-send-email-kevin@tyndur.org> This adds a new CDI header cdi/mem.h. It unifies memory allocations (and memory areas passed from external sources) for different types of DMA, allows the OS layer to back it by shared memory (makes sense in a microkernel approach) and probably some more nice things. What cdi_mem_alloc/free are good for is obvious, I hope. To explain the use of the other functions, consider the following. Let's take a disk driver as an example. Instead of buffer/size its write function will directly get a memory area from the OS. The OS might already have allocated the memory physically contiguous, but it doesn't need to do so. The driver calls cdi_mem_require_flags which copies the data into a suited buffer - but if the OS already did the right thing, it's a no-op. cdi_mem_copy is for the other way round. Now the disk driver wants to read something from its disk. It gets a memory area from the OS and uses cdi_mem_require_flags to get something usable for DMA, which may or may not involve a copy. When the disk has transferred all the data, the driver uses cdi_mem_copy to make sure that the read data ends up in the buffer it was passed - and again, if the buffer had already the right flags this will be a no-op. Signed-off-by: Kevin Wolf --- v2: - Added s/g lists - Added alignment field in flags - Removed requirement to work only on complete pages include/cdi/mem.h | 229 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 229 insertions(+), 0 deletions(-) create mode 100644 include/cdi/mem.h diff --git a/include/cdi/mem.h b/include/cdi/mem.h new file mode 100644 index 0000000..0061a72 --- /dev/null +++ b/include/cdi/mem.h @@ -0,0 +1,229 @@ +/* + * 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 + * \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); + +/** + * \german + * Gibt einen durch cdi_mem_alloc reservierten Speicherbereich frei + * \endgerman + * \english + * Frees a memory area that was previously allocated by cdi_mem_alloc + * \endenglish + */ +void cdi_mem_free(struct cdi_memory_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 matthew at theiselins.net Sun Feb 7 00:52:27 2010 From: matthew at theiselins.net (Matthew Iselin) Date: Sun, 7 Feb 2010 09:52:27 +1000 Subject: [cdi-devel] [PATCH v2] mem.h: Handling memory areas In-Reply-To: <1265472340-31626-1-git-send-email-kevin@tyndur.org> References: <1265472340-31626-1-git-send-email-kevin@tyndur.org> Message-ID: On Sun, Feb 7, 2010 at 2:05 AM, Kevin Wolf wrote: > This adds a new CDI header cdi/mem.h. It unifies memory allocations > (and memory areas passed from external sources) for different types > of DMA, allows the OS layer to back it by shared memory (makes sense > in a microkernel approach) and probably some more nice things. > > What cdi_mem_alloc/free are good for is obvious, I hope. > > To explain the use of the other functions, consider the following. > Let's take a disk driver as an example. Instead of buffer/size its > write function will directly get a memory area from the OS. The OS might > already have allocated the memory physically contiguous, but it doesn't > need to do so. The driver calls cdi_mem_require_flags which copies the > data into a suited buffer - but if the OS already did the right thing, > it's a no-op. > > cdi_mem_copy is for the other way round. Now the disk driver wants to > read something from its disk. It gets a memory area from the OS and uses > cdi_mem_require_flags to get something usable for DMA, which may or may > not involve a copy. When the disk has transferred all the data, the > driver uses cdi_mem_copy to make sure that the read data ends up in the > buffer it was passed - and again, if the buffer had already the right > flags this will be a no-op. > > Signed-off-by: Kevin Wolf We can figure out a better name for cdi_mem_require_flags in the future. For now it'd be nice to actually get this implemented. Acked-by: Matthew Iselin From kevin at tyndur.org Thu Feb 11 00:01:06 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Thu, 11 Feb 2010 00:01:06 +0100 Subject: [cdi-devel] [PATCH 0/4] mem.h - Part 1 Message-ID: <1265842870-7523-1-git-send-email-kevin@tyndur.org> Okay, so here is the first part of the conversion. The header is mostly unchanged, I only added a function cdi_mem_map which maps a given physical address. The rest of the patches replace the memory management functions of misc.h with the mem.h ones. Once this is in, the next step is to convert interfaces like send_packet to take a cdi_mem_area as a parameter. Kevin Wolf (4): mem.h: Handling memory areas pcnet: Factor init block function out cdi: Replace cdi_alloc_phys_mem/addr cdi: Remove obsolete functions ata/device.c | 16 ++- ata/device.h | 4 +- ata/request.c | 2 +- e1000/device.c | 19 +++- e1000/device.h | 2 +- include/cdi-osdep.h | 11 ++ include/cdi/mem.h | 255 +++++++++++++++++++++++++++++++++++++++++++++ include/cdi/misc.h | 23 ---- ne2k/include/ne2k.h | 4 +- ne2k/ne2k.c | 13 ++- pcnet/include/pcnet.h | 3 - pcnet/pcnet.c | 127 ++++++++++++++--------- rtl8139/include/rtl8139.h | 4 +- rtl8139/rtl8139.c | 13 ++- sis900/device.c | 15 ++- sis900/device.h | 2 +- 16 files changed, 409 insertions(+), 104 deletions(-) create mode 100644 include/cdi/mem.h From kevin at tyndur.org Thu Feb 11 00:01:07 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Thu, 11 Feb 2010 00:01:07 +0100 Subject: [cdi-devel] [PATCH 1/4] mem.h: Handling memory areas In-Reply-To: <1265842870-7523-1-git-send-email-kevin@tyndur.org> References: <1265842870-7523-1-git-send-email-kevin@tyndur.org> Message-ID: <1265842870-7523-2-git-send-email-kevin@tyndur.org> This adds a new CDI header cdi/mem.h. It unifies memory allocations (and memory areas passed from external sources) for different types of DMA, allows the OS layer to back it by shared memory (makes sense in a microkernel approach) and probably some more nice things. What cdi_mem_alloc/map/free are good for is obvious, I hope. To explain the use of the other functions, consider the following. Let's take a disk driver as an example. Instead of buffer/size its write function will directly get a memory area from the OS. The OS might already have allocated the memory physically contiguous, but it doesn't need to do so. The driver calls cdi_mem_require_flags which copies the data into a suited buffer - but if the OS already did the right thing, it's a no-op. cdi_mem_copy is for the other way round. Now the disk driver wants to read something from its disk. It gets a memory area from the OS and uses cdi_mem_require_flags to get something usable for DMA, which may or may not involve a copy. When the disk has transferred all the data, the driver uses cdi_mem_copy to make sure that the read data ends up in the buffer it was passed - and again, if the buffer had already the right flags this will be a no-op. Signed-off-by: Kevin Wolf --- include/cdi-osdep.h | 11 ++ include/cdi/mem.h | 255 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 266 insertions(+), 0 deletions(-) create mode 100644 include/cdi/mem.h diff --git a/include/cdi-osdep.h b/include/cdi-osdep.h index f026352..279001a 100644 --- a/include/cdi-osdep.h +++ b/include/cdi-osdep.h @@ -56,4 +56,15 @@ typedef struct { } 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/include/cdi/mem.h b/include/cdi/mem.h new file mode 100644 index 0000000..08837f7 --- /dev/null +++ b/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 Thu Feb 11 00:01:08 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Thu, 11 Feb 2010 00:01:08 +0100 Subject: [cdi-devel] [PATCH 2/4] pcnet: Factor init block function out In-Reply-To: <1265842870-7523-1-git-send-email-kevin@tyndur.org> References: <1265842870-7523-1-git-send-email-kevin@tyndur.org> Message-ID: <1265842870-7523-3-git-send-email-kevin@tyndur.org> * pcnet: The initialization block a is temporary structure and doesn't belong in pcnet_device. The code for sending it is split out into its own function to make the switch to cdi_mem_alloc/free easier. Signed-off-by: Kevin Wolf --- pcnet/include/pcnet.h | 3 -- pcnet/pcnet.c | 84 +++++++++++++++++++++++++++++-------------------- 2 files changed, 50 insertions(+), 37 deletions(-) diff --git a/pcnet/include/pcnet.h b/pcnet/include/pcnet.h index 000862c..6c29a56 100644 --- a/pcnet/include/pcnet.h +++ b/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/pcnet/pcnet.c b/pcnet/pcnet.c index a157094..e4500dc 100644 --- a/pcnet/pcnet.c +++ b/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 Thu Feb 11 00:01:09 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Thu, 11 Feb 2010 00:01:09 +0100 Subject: [cdi-devel] [PATCH 3/4] cdi: Replace cdi_alloc_phys_mem/addr In-Reply-To: <1265842870-7523-1-git-send-email-kevin@tyndur.org> References: <1265842870-7523-1-git-send-email-kevin@tyndur.org> Message-ID: <1265842870-7523-4-git-send-email-kevin@tyndur.org> * In all drivers, replace cdi_alloc_phys_mem by cdi_mem_alloc * In all drivers, replace cdi_alloc_phys_addr by cdi_mem_map Signed-off-by: Kevin Wolf --- ata/device.c | 16 +++++++++--- ata/device.h | 4 +- ata/request.c | 2 +- e1000/device.c | 19 +++++++++---- e1000/device.h | 2 +- ne2k/include/ne2k.h | 4 +- ne2k/ne2k.c | 13 +++++++-- pcnet/pcnet.c | 61 +++++++++++++++++++++++++++----------------- rtl8139/include/rtl8139.h | 4 +- rtl8139/rtl8139.c | 13 +++++++-- sis900/device.c | 15 ++++++++--- sis900/device.h | 2 +- 12 files changed, 102 insertions(+), 53 deletions(-) diff --git a/ata/device.c b/ata/device.c index dd087c3..6e33d52 100644 --- a/ata/device.c +++ b/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/ata/device.h b/ata/device.h index efb3f6f..6c438e0 100644 --- a/ata/device.h +++ b/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/ata/request.c b/ata/request.c index e98ee60..9d618c7 100644 --- a/ata/request.c +++ b/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/e1000/device.c b/e1000/device.c index b21df2f..1b31987 100644 --- a/e1000/device.c +++ b/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/e1000/device.h b/e1000/device.h index 9266e0f..2a10365 100644 --- a/e1000/device.h +++ b/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/ne2k/include/ne2k.h b/ne2k/include/ne2k.h index 585eab5..0102ce8 100644 --- a/ne2k/include/ne2k.h +++ b/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/ne2k/ne2k.c b/ne2k/ne2k.c index 7f1262e..d3fa019 100644 --- a/ne2k/ne2k.c +++ b/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/pcnet/pcnet.c b/pcnet/pcnet.c index e4500dc..ea0b4d7 100644 --- a/pcnet/pcnet.c +++ b/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/rtl8139/include/rtl8139.h b/rtl8139/include/rtl8139.h index 3ec81b0..aafa71f 100644 --- a/rtl8139/include/rtl8139.h +++ b/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/rtl8139/rtl8139.c b/rtl8139/rtl8139.c index 600f3e9..6571c56 100644 --- a/rtl8139/rtl8139.c +++ b/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/sis900/device.c b/sis900/device.c index 30c6d39..aa5d7c8 100644 --- a/sis900/device.c +++ b/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/sis900/device.h b/sis900/device.h index cd110c0..7698d2f 100644 --- a/sis900/device.h +++ b/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 Thu Feb 11 00:01:10 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Thu, 11 Feb 2010 00:01:10 +0100 Subject: [cdi-devel] [PATCH 4/4] cdi: Remove obsolete functions In-Reply-To: <1265842870-7523-1-git-send-email-kevin@tyndur.org> References: <1265842870-7523-1-git-send-email-kevin@tyndur.org> Message-ID: <1265842870-7523-5-git-send-email-kevin@tyndur.org> - misc.h: Removed memory management functions Signed-off-by: Kevin Wolf --- include/cdi/misc.h | 23 ----------------------- 1 files changed, 0 insertions(+), 23 deletions(-) diff --git a/include/cdi/misc.h b/include/cdi/misc.h index 183d32b..a9a6da6 100644 --- a/include/cdi/misc.h +++ b/include/cdi/misc.h @@ -61,29 +61,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. -- 1.6.0.2 From matthew at theiselins.net Thu Feb 11 02:13:29 2010 From: matthew at theiselins.net (Matthew Iselin) Date: Thu, 11 Feb 2010 11:13:29 +1000 Subject: [cdi-devel] [PATCH] Change cdi.h to use angle brackets for cdi-osdep.h include Message-ID: <1265850809-2772-1-git-send-email-matthew@theiselins.net> Hi, This patch just changes cdi.h to use angle brackets when including cdi-osdep.h so that the compiler searches include directories (eg, -I) *first* rather than checking the local directory first. Without this patch the wrong cdi-osdep.h gets included on Pedigree. Signed-off-by: Matthew Iselin --- include/cdi.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/include/cdi.h b/include/cdi.h index d1a0b11..34438b0 100644 --- a/include/cdi.h +++ b/include/cdi.h @@ -102,7 +102,7 @@ #include -#include "cdi-osdep.h" +#include #include "cdi/lists.h" typedef enum { -- 1.6.4.msysgit.0 From matthew at theiselins.net Thu Feb 11 02:39:59 2010 From: matthew at theiselins.net (Matthew Iselin) Date: Thu, 11 Feb 2010 11:39:59 +1000 Subject: [cdi-devel] [PATCH 2/4] pcnet: Factor init block function out In-Reply-To: <1265842870-7523-3-git-send-email-kevin@tyndur.org> References: <1265842870-7523-1-git-send-email-kevin@tyndur.org> <1265842870-7523-3-git-send-email-kevin@tyndur.org> Message-ID: On Thu, Feb 11, 2010 at 9:01 AM, Kevin Wolf wrote: > * pcnet: The initialization block a is temporary structure and doesn't belong > ?in pcnet_device. The code for sending it is split out into its own function > ?to make the switch to cdi_mem_alloc/free easier. > > Signed-off-by: Kevin Wolf Acked-by: Matthew Iselin From matthew at theiselins.net Thu Feb 11 02:42:34 2010 From: matthew at theiselins.net (Matthew Iselin) Date: Thu, 11 Feb 2010 11:42:34 +1000 Subject: [cdi-devel] [PATCH 1/4] mem.h: Handling memory areas In-Reply-To: <1265842870-7523-2-git-send-email-kevin@tyndur.org> References: <1265842870-7523-1-git-send-email-kevin@tyndur.org> <1265842870-7523-2-git-send-email-kevin@tyndur.org> Message-ID: On Thu, Feb 11, 2010 at 9:01 AM, Kevin Wolf wrote: > This adds a new CDI header cdi/mem.h. It unifies memory allocations > (and memory areas passed from external sources) for different types > of DMA, allows the OS layer to back it by shared memory (makes sense > in a microkernel approach) and probably some more nice things. > > What cdi_mem_alloc/map/free are good for is obvious, I hope. > > To explain the use of the other functions, consider the following. > Let's take a disk driver as an example. Instead of buffer/size its > write function will directly get a memory area from the OS. The OS might > already have allocated the memory physically contiguous, but it doesn't > need to do so. The driver calls cdi_mem_require_flags which copies the > data into a suited buffer - but if the OS already did the right thing, > it's a no-op. > > cdi_mem_copy is for the other way round. Now the disk driver wants to > read something from its disk. It gets a memory area from the OS and uses > cdi_mem_require_flags to get something usable for DMA, which may or may > not involve a copy. When the disk has transferred all the data, the > driver uses cdi_mem_copy to make sure that the read data ends up in the > buffer it was passed - and again, if the buffer had already the right > flags this will be a no-op. > > Signed-off-by: Kevin Wolf We can keep trying to find an alternative name for cdi_mem_require_flags later. It's only the name of a function, after all... A quick find and replace can fix that later on. Acked-by: Matthew Iselin From matthew at theiselins.net Thu Feb 11 02:43:43 2010 From: matthew at theiselins.net (Matthew Iselin) Date: Thu, 11 Feb 2010 11:43:43 +1000 Subject: [cdi-devel] [PATCH 3/4] cdi: Replace cdi_alloc_phys_mem/addr In-Reply-To: <1265842870-7523-4-git-send-email-kevin@tyndur.org> References: <1265842870-7523-1-git-send-email-kevin@tyndur.org> <1265842870-7523-4-git-send-email-kevin@tyndur.org> Message-ID: On Thu, Feb 11, 2010 at 9:01 AM, Kevin Wolf wrote: > * In all drivers, replace cdi_alloc_phys_mem by cdi_mem_alloc > * In all drivers, replace cdi_alloc_phys_addr by cdi_mem_map > > Signed-off-by: Kevin Wolf Looks much better now. Acked-by: Matthew Iselin From matthew at theiselins.net Thu Feb 11 02:44:18 2010 From: matthew at theiselins.net (Matthew Iselin) Date: Thu, 11 Feb 2010 11:44:18 +1000 Subject: [cdi-devel] [PATCH 4/4] cdi: Remove obsolete functions In-Reply-To: <1265842870-7523-5-git-send-email-kevin@tyndur.org> References: <1265842870-7523-1-git-send-email-kevin@tyndur.org> <1265842870-7523-5-git-send-email-kevin@tyndur.org> Message-ID: 2010/2/11 Kevin Wolf : > - misc.h: Removed memory management functions > > Signed-off-by: Kevin Wolf Acked-by: Matthew Iselin From matthew at theiselins.net Fri Feb 12 10:00:48 2010 From: matthew at theiselins.net (Matthew Iselin) Date: Fri, 12 Feb 2010 19:00:48 +1000 Subject: [cdi-devel] [PATCH] Change CDI headers to use angle brackets for other CDI headers Message-ID: <1265965248-3548-1-git-send-email-matthew@theiselins.net> Signed-off-by: Matthew Iselin --- include/cdi.h | 4 ++-- include/cdi/bios.h | 2 +- include/cdi/dma.h | 5 +++-- include/cdi/fs.h | 6 +++--- include/cdi/misc.h | 2 +- include/cdi/net.h | 2 +- include/cdi/pci.h | 6 +++--- include/cdi/scsi.h | 2 +- include/cdi/storage.h | 2 +- 9 files changed, 16 insertions(+), 15 deletions(-) diff --git a/include/cdi.h b/include/cdi.h index d1a0b11..c77e071 100644 --- a/include/cdi.h +++ b/include/cdi.h @@ -102,8 +102,8 @@ #include -#include "cdi-osdep.h" -#include "cdi/lists.h" +#include +#include typedef enum { CDI_UNKNOWN = 0, diff --git a/include/cdi/bios.h b/include/cdi/bios.h index 461a6c5..dad8d9e 100644 --- a/include/cdi/bios.h +++ b/include/cdi/bios.h @@ -13,7 +13,7 @@ #include -#include "cdi/lists.h" +#include struct cdi_bios_registers { uint16_t ax; diff --git a/include/cdi/dma.h b/include/cdi/dma.h index 3eca721..9a33a86 100644 --- a/include/cdi/dma.h +++ b/include/cdi/dma.h @@ -13,8 +13,9 @@ #include #include -#include "cdi.h" -#include "cdi-osdep.h" + +#include +#include struct cdi_dma_handle { uint8_t channel; diff --git a/include/cdi/fs.h b/include/cdi/fs.h index c464d0d..6a9f3eb 100644 --- a/include/cdi/fs.h +++ b/include/cdi/fs.h @@ -19,9 +19,9 @@ #include -#include "cdi.h" -#include "cdi/lists.h" -#include "cdi/cache.h" +#include +#include +#include #include diff --git a/include/cdi/misc.h b/include/cdi/misc.h index 2049c62..3897b47 100644 --- a/include/cdi/misc.h +++ b/include/cdi/misc.h @@ -13,7 +13,7 @@ #include -#include "cdi.h" +#include #ifdef __cplusplus extern "C" { diff --git a/include/cdi/net.h b/include/cdi/net.h index 9d4f0f0..eea24c1 100644 --- a/include/cdi/net.h +++ b/include/cdi/net.h @@ -20,7 +20,7 @@ #include #include -#include "cdi.h" +#include struct cdi_net_device { struct cdi_device dev; diff --git a/include/cdi/pci.h b/include/cdi/pci.h index 1192332..626bed2 100644 --- a/include/cdi/pci.h +++ b/include/cdi/pci.h @@ -13,9 +13,9 @@ #include -#include "cdi.h" -#include "cdi-osdep.h" -#include "cdi/lists.h" +#include +#include +#include struct cdi_pci_device { struct cdi_bus_data bus_data; diff --git a/include/cdi/scsi.h b/include/cdi/scsi.h index 6d12b91..8edccbf 100644 --- a/include/cdi/scsi.h +++ b/include/cdi/scsi.h @@ -20,7 +20,7 @@ #include #include -#include "cdi.h" +#include /// SCSI-Paket struct cdi_scsi_packet { diff --git a/include/cdi/storage.h b/include/cdi/storage.h index 4963b68..aaffc78 100644 --- a/include/cdi/storage.h +++ b/include/cdi/storage.h @@ -19,7 +19,7 @@ #include -#include "cdi.h" +#include struct cdi_storage_device { struct cdi_device dev; -- 1.6.4.msysgit.0 From matthew at theiselins.net Fri Feb 12 10:03:14 2010 From: matthew at theiselins.net (Matthew Iselin) Date: Fri, 12 Feb 2010 19:03:14 +1000 Subject: [cdi-devel] [PATCH] Change cdi.h to use angle brackets for cdi-osdep.h include In-Reply-To: <1265850809-2772-1-git-send-email-matthew@theiselins.net> References: <1265850809-2772-1-git-send-email-matthew@theiselins.net> Message-ID: On Thu, Feb 11, 2010 at 11:13 AM, Matthew Iselin wrote: > Hi, > > This patch just changes cdi.h to use angle brackets when including cdi-osdep.h > so that the compiler searches include directories (eg, -I) *first* > rather than checking the local directory first. > > Without this patch the wrong cdi-osdep.h gets included on Pedigree. > > Signed-off-by: Matthew Iselin Patch made obsolete by a later one on this mailing list. From max at tyndur.org Fri Feb 12 11:03:33 2010 From: max at tyndur.org (Max Reitz) Date: Fri, 12 Feb 2010 11:03:33 +0100 Subject: [cdi-devel] [PATCH] Change CDI headers to use angle brackets for other CDI headers In-Reply-To: <1265965248-3548-1-git-send-email-matthew@theiselins.net> References: <1265965248-3548-1-git-send-email-matthew@theiselins.net> Message-ID: <4B752775.9040407@tyndur.org> Matthew Iselin wrote: > Signed-off-by: Matthew Iselin Acked-by: Max Reitz From max at tyndur.org Fri Feb 12 11:23:56 2010 From: max at tyndur.org (Max Reitz) Date: Fri, 12 Feb 2010 11:23:56 +0100 Subject: [cdi-devel] [PATCH 1/4] mem.h: Handling memory areas In-Reply-To: <1265842870-7523-2-git-send-email-kevin@tyndur.org> References: <1265842870-7523-1-git-send-email-kevin@tyndur.org> <1265842870-7523-2-git-send-email-kevin@tyndur.org> Message-ID: <4B752C3C.7080805@tyndur.org> Kevin Wolf wrote: > This adds a new CDI header cdi/mem.h. It unifies memory allocations > (and memory areas passed from external sources) for different types > of DMA, allows the OS layer to back it by shared memory (makes sense > in a microkernel approach) and probably some more nice things. Looks nice after some reading (though I still don't like "z.B."). ;-) Acked-by: Max Reitz From max at tyndur.org Fri Feb 12 11:37:09 2010 From: max at tyndur.org (Max Reitz) Date: Fri, 12 Feb 2010 11:37:09 +0100 Subject: [cdi-devel] [PATCH 2/4] pcnet: Factor init block function out In-Reply-To: <1265842870-7523-3-git-send-email-kevin@tyndur.org> References: <1265842870-7523-1-git-send-email-kevin@tyndur.org> <1265842870-7523-3-git-send-email-kevin@tyndur.org> Message-ID: <4B752F55.9010404@tyndur.org> Kevin Wolf wrote: > * pcnet: The initialization block a is temporary structure and doesn't belong > in pcnet_device. The code for sending it is split out into its own function > to make the switch to cdi_mem_alloc/free easier. > > Signed-off-by: Kevin Wolf Looks good so far. Acked-by: Max Reitz From max at tyndur.org Fri Feb 12 11:43:38 2010 From: max at tyndur.org (Max Reitz) Date: Fri, 12 Feb 2010 11:43:38 +0100 Subject: [cdi-devel] [PATCH 3/4] cdi: Replace cdi_alloc_phys_mem/addr In-Reply-To: <1265842870-7523-4-git-send-email-kevin@tyndur.org> References: <1265842870-7523-1-git-send-email-kevin@tyndur.org> <1265842870-7523-4-git-send-email-kevin@tyndur.org> Message-ID: <4B7530DA.6060102@tyndur.org> Kevin Wolf wrote: > * In all drivers, replace cdi_alloc_phys_mem by cdi_mem_alloc > * In all drivers, replace cdi_alloc_phys_addr by cdi_mem_map > > Signed-off-by: Kevin Wolf Acked-by: Max Reitz From max at tyndur.org Fri Feb 12 11:46:22 2010 From: max at tyndur.org (Max Reitz) Date: Fri, 12 Feb 2010 11:46:22 +0100 Subject: [cdi-devel] [PATCH 4/4] cdi: Remove obsolete functions In-Reply-To: <1265842870-7523-5-git-send-email-kevin@tyndur.org> References: <1265842870-7523-1-git-send-email-kevin@tyndur.org> <1265842870-7523-5-git-send-email-kevin@tyndur.org> Message-ID: <4B75317E.5030708@tyndur.org> Kevin Wolf wrote: > - misc.h: Removed memory management functions > > Signed-off-by: Kevin Wolf Acked-by: Max Reitz From redelman at gmail.com Fri Feb 12 15:24:04 2010 From: redelman at gmail.com (Rich Edelman) Date: Fri, 12 Feb 2010 08:24:04 -0600 Subject: [cdi-devel] [PATCH] Change CDI headers to use angle brackets for other CDI headers In-Reply-To: <1265965248-3548-1-git-send-email-matthew@theiselins.net> References: <1265965248-3548-1-git-send-email-matthew@theiselins.net> Message-ID: <61acd8d31002120624l1692b017m66e09f17aceb085@mail.gmail.com> On Fri, Feb 12, 2010 at 3:00 AM, Matthew Iselin wrote: > > Signed-off-by: Matthew Iselin Acked-by: Rich Edelman From redelman at gmail.com Fri Feb 12 15:26:38 2010 From: redelman at gmail.com (Rich Edelman) Date: Fri, 12 Feb 2010 08:26:38 -0600 Subject: [cdi-devel] [PATCH 1/4] mem.h: Handling memory areas In-Reply-To: <1265842870-7523-2-git-send-email-kevin@tyndur.org> References: <1265842870-7523-1-git-send-email-kevin@tyndur.org> <1265842870-7523-2-git-send-email-kevin@tyndur.org> Message-ID: <61acd8d31002120626n1306a946wea221c8c713ef100@mail.gmail.com> On Wed, Feb 10, 2010 at 5:01 PM, Kevin Wolf wrote: > This adds a new CDI header cdi/mem.h. It unifies memory allocations > (and memory areas passed from external sources) for different types > of DMA, allows the OS layer to back it by shared memory (makes sense > in a microkernel approach) and probably some more nice things. > Signed-off-by: Kevin Wolf Acked-by: Rich Edelman From redelman at gmail.com Fri Feb 12 15:27:36 2010 From: redelman at gmail.com (Rich Edelman) Date: Fri, 12 Feb 2010 08:27:36 -0600 Subject: [cdi-devel] [PATCH 2/4] pcnet: Factor init block function out In-Reply-To: <1265842870-7523-3-git-send-email-kevin@tyndur.org> References: <1265842870-7523-1-git-send-email-kevin@tyndur.org> <1265842870-7523-3-git-send-email-kevin@tyndur.org> Message-ID: <61acd8d31002120627w210420ccpcb3adcfea2e15058@mail.gmail.com> On Wed, Feb 10, 2010 at 5:01 PM, Kevin Wolf wrote: > * pcnet: The initialization block a is temporary structure and doesn't belong > ?in pcnet_device. The code for sending it is split out into its own function > ?to make the switch to cdi_mem_alloc/free easier. > > Signed-off-by: Kevin Wolf Acked-by: Rich Edelman From redelman at gmail.com Fri Feb 12 15:28:32 2010 From: redelman at gmail.com (Rich Edelman) Date: Fri, 12 Feb 2010 08:28:32 -0600 Subject: [cdi-devel] [PATCH 3/4] cdi: Replace cdi_alloc_phys_mem/addr In-Reply-To: <1265842870-7523-4-git-send-email-kevin@tyndur.org> References: <1265842870-7523-1-git-send-email-kevin@tyndur.org> <1265842870-7523-4-git-send-email-kevin@tyndur.org> Message-ID: <61acd8d31002120628t15ea54dfp2c5c56d4cde7ac9a@mail.gmail.com> On Wed, Feb 10, 2010 at 5:01 PM, Kevin Wolf wrote: > * In all drivers, replace cdi_alloc_phys_mem by cdi_mem_alloc > * In all drivers, replace cdi_alloc_phys_addr by cdi_mem_map > > Signed-off-by: Kevin Wolf Acked-by: Rich Edelman From redelman at gmail.com Fri Feb 12 15:30:19 2010 From: redelman at gmail.com (Rich Edelman) Date: Fri, 12 Feb 2010 08:30:19 -0600 Subject: [cdi-devel] [PATCH 4/4] cdi: Remove obsolete functions In-Reply-To: <1265842870-7523-5-git-send-email-kevin@tyndur.org> References: <1265842870-7523-1-git-send-email-kevin@tyndur.org> <1265842870-7523-5-git-send-email-kevin@tyndur.org> Message-ID: <61acd8d31002120630w4f73c9dat3a5796166c9f4d29@mail.gmail.com> 2010/2/10 Kevin Wolf : > - misc.h: Removed memory management functions > > Signed-off-by: Kevin Wolf Acked-by: Rich Edelman From kevin at tyndur.org Sat Feb 13 00:26:29 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 13 Feb 2010 00:26:29 +0100 Subject: [cdi-devel] [PATCH] Change CDI headers to use angle brackets for other CDI headers In-Reply-To: <1265965248-3548-1-git-send-email-matthew@theiselins.net> References: <1265965248-3548-1-git-send-email-matthew@theiselins.net> Message-ID: <20100212232629.GB23684@silvanus> On Fri, Feb 12, 2010 at 07:00:48PM +1000, Matthew Iselin wrote: > > Signed-off-by: Matthew Iselin > --- > include/cdi.h | 4 ++-- > include/cdi/bios.h | 2 +- > include/cdi/dma.h | 5 +++-- > include/cdi/fs.h | 6 +++--- > include/cdi/misc.h | 2 +- > include/cdi/net.h | 2 +- > include/cdi/pci.h | 6 +++--- > include/cdi/scsi.h | 2 +- > include/cdi/storage.h | 2 +- > 9 files changed, 16 insertions(+), 15 deletions(-) Thanks, applied. From kevin at tyndur.org Sat Feb 13 00:27:00 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 13 Feb 2010 00:27:00 +0100 Subject: [cdi-devel] [PATCH 0/4] mem.h - Part 1 In-Reply-To: <1265842870-7523-1-git-send-email-kevin@tyndur.org> References: <1265842870-7523-1-git-send-email-kevin@tyndur.org> Message-ID: <20100212232659.GC23684@silvanus> On Thu, Feb 11, 2010 at 12:01:06AM +0100, Kevin Wolf wrote: > Okay, so here is the first part of the conversion. The header is mostly > unchanged, I only added a function cdi_mem_map which maps a given > physical address. The rest of the patches replace the memory management > functions of misc.h with the mem.h ones. > > Once this is in, the next step is to convert interfaces like > send_packet to take a cdi_mem_area as a parameter. > > Kevin Wolf (4): > mem.h: Handling memory areas > pcnet: Factor init block function out > cdi: Replace cdi_alloc_phys_mem/addr > cdi: Remove obsolete functions Applied all. From matthew at theiselins.net Sat Feb 13 00:26:57 2010 From: matthew at theiselins.net (Matthew Iselin) Date: Sat, 13 Feb 2010 09:26:57 +1000 Subject: [cdi-devel] [PATCH] Add cdi_provide_device prototype to cdi.h Message-ID: <1266017217-7840-1-git-send-email-matthew@theiselins.net> Hi, This patch provides a prototype and initial documentation for the cdi_provide_device function. Signed-off-by: Matthew Iselin --- include/cdi.h | 37 +++++++++++++++++++++++++++++++++++++ 1 files changed, 37 insertions(+), 0 deletions(-) diff --git a/include/cdi.h b/include/cdi.h index c77e071..5cbb4a6 100644 --- a/include/cdi.h +++ b/include/cdi.h @@ -290,6 +290,43 @@ void cdi_driver_destroy(struct cdi_driver* driver); */ void cdi_driver_register(struct cdi_driver* driver); +/** + * \english + * Allows a driver to inform the operating system that a new device has become + * available. + * + * The rationale behind cdi_provide_device is to allow controller interfaces + * to provide devices on their bus which may not be available through the + * conventional PCI bus (for example, a USB mass storage device). This also + * allows devices to inform the OS of the presence of other devices outside + * of the context of a controller interface, where necessary. + * + * The operating system should determine which driver to load (or inform of + * the new device) based on the cdi_bus_data struct passed. How the operating + * system decides which driver to load/inform is not defined by CDI. An example + * would be a simple list generated from a script which parses each driver in + * the source tree, finds relevant cdi_bus_data structs, and adds them to a + * list which maps the structs to a string. The OS can then use that string to + * load a driver somehow. + * + * Whilst CDI could provide a pre-defined list of mappings for operating + * systems to use when implementing cdi_provide_device, it was decided that + * this would make the interface too rigid. Whilst this method requires a + * little more effort from the CDI implementor, it also allows operating + * systems to load non-CDI drivers (eg, from a native driver interface) as + * defined by the OS-specific mapping list. This would be impossible if CDI + * rigidly enforced a specific method. + * + * Operating systems may also choose to implement cdi_provide_device and then + * use it when iterating over the PCI bus in order to load drivers dynamically + * (effectively treating coldplug devices as hotplugged before boot). + * + * @return 0 on success, -1 if an error was encountered, and -2 if no driver + * was found for the device. + * \endenglish + */ +int cdi_provide_device(struct cdi_bus_data* device); + #endif /*\@}*/ -- 1.6.4.msysgit.0 From matthew at theiselins.net Sat Feb 13 01:12:42 2010 From: matthew at theiselins.net (Matthew Iselin) Date: Sat, 13 Feb 2010 10:12:42 +1000 Subject: [cdi-devel] [PATCH v2] Add cdi_provide_device prototype to cdi.h Message-ID: <1266019962-5748-1-git-send-email-matthew@theiselins.net> Hi, This patch provides a prototype and initial documentation for the cdi_provide_device function. This second version no longer includes the "No driver available" return value. Signed-off-by: Matthew Iselin --- include/cdi.h | 37 +++++++++++++++++++++++++++++++++++++ 1 files changed, 37 insertions(+), 0 deletions(-) diff --git a/include/cdi.h b/include/cdi.h index c77e071..5cbb4a6 100644 --- a/include/cdi.h +++ b/include/cdi.h @@ -290,6 +290,42 @@ void cdi_driver_destroy(struct cdi_driver* driver); */ void cdi_driver_register(struct cdi_driver* driver); +/** + * \english + * Allows a driver to inform the operating system that a new device has become + * available. + * + * The rationale behind cdi_provide_device is to allow controller interfaces + * to provide devices on their bus which may not be available through the + * conventional PCI bus (for example, a USB mass storage device). This also + * allows devices to inform the OS of the presence of other devices outside + * of the context of a controller interface, where necessary. + * + * The operating system should determine which driver to load (or inform of + * the new device) based on the cdi_bus_data struct passed. How the operating + * system decides which driver to load/inform is not defined by CDI. An example + * would be a simple list generated from a script which parses each driver in + * the source tree, finds relevant cdi_bus_data structs, and adds them to a + * list which maps the structs to a string. The OS can then use that string to + * load a driver somehow. + * + * Whilst CDI could provide a pre-defined list of mappings for operating + * systems to use when implementing cdi_provide_device, it was decided that + * this would make the interface too rigid. Whilst this method requires a + * little more effort from the CDI implementor, it also allows operating + * systems to load non-CDI drivers (eg, from a native driver interface) as + * defined by the OS-specific mapping list. This would be impossible if CDI + * rigidly enforced a specific method. + * + * Operating systems may also choose to implement cdi_provide_device and then + * use it when iterating over the PCI bus in order to load drivers dynamically + * (effectively treating coldplug devices as hotplugged before boot). + * + * @return 0 on success or -1 if an error was encountered. + * \endenglish + */ +int cdi_provide_device(struct cdi_bus_data* device); + #endif /*\@}*/ -- 1.6.4.msysgit.0 From redelman at gmail.com Sat Feb 13 01:21:02 2010 From: redelman at gmail.com (Rich Edelman) Date: Fri, 12 Feb 2010 18:21:02 -0600 Subject: [cdi-devel] [PATCH v2] Add cdi_provide_device prototype to cdi.h In-Reply-To: <1266019962-5748-1-git-send-email-matthew@theiselins.net> References: <1266019962-5748-1-git-send-email-matthew@theiselins.net> Message-ID: <61acd8d31002121621ta97b3dfua15b159003f962d9@mail.gmail.com> On Fri, Feb 12, 2010 at 6:12 PM, Matthew Iselin wrote: > Hi, > > This patch provides a prototype and initial documentation for the > cdi_provide_device function. > > This second version no longer includes the "No driver available" return > value. > > Signed-off-by: Matthew Iselin Acked-by: Rich Edelman From max at tyndur.org Sat Feb 13 01:39:23 2010 From: max at tyndur.org (Max Reitz) Date: Sat, 13 Feb 2010 01:39:23 +0100 Subject: [cdi-devel] [PATCH v2] Add cdi_provide_device prototype to cdi.h In-Reply-To: <1266019962-5748-1-git-send-email-matthew@theiselins.net> References: <1266019962-5748-1-git-send-email-matthew@theiselins.net> Message-ID: <4B75F4BB.5000103@tyndur.org> Matthew Iselin wrote: > Hi, > > This patch provides a prototype and initial documentation for the > cdi_provide_device function. > > Signed-off-by: Matthew Iselin Acked-by: Max Reitz From kevin at tyndur.org Sat Feb 13 12:08:32 2010 From: kevin at tyndur.org (Kevin Wolf) Date: Sat, 13 Feb 2010 12:08:32 +0100 Subject: [cdi-devel] [PATCH v2] Add cdi_provide_device prototype to cdi.h In-Reply-To: <1266019962-5748-1-git-send-email-matthew@theiselins.net> References: <1266019962-5748-1-git-send-email-matthew@theiselins.net> Message-ID: <20100213110831.GA16926@silvanus> On Sat, Feb 13, 2010 at 10:12:42AM +1000, Matthew Iselin wrote: > Hi, > > This patch provides a prototype and initial documentation for the > cdi_provide_device function. > > This second version no longer includes the "No driver available" return > value. > > Signed-off-by: Matthew Iselin Thanks, applied. Now I'm curious what the information for the driver lists is going to look like. This will be an important step for the driver infrastructure. Kevin