CDI Drivers

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
nevar
Posts: 12
Joined: Fri Feb 02, 2007 8:04 am

CDI Drivers

Post by nevar »

Hi,
As CDI (Common Driver Interface) is I think german project, it is hard to me to find is there any drivers writen with CDI specyfication in english language.
And if there is any developer of CDI here, I would like to say that it would be useful to get detailed documentation of CDI and driver source with commentation in english language.
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: CDI Drivers

Post by Kevin »

You can find some basic English documentation at http://lpt.tyndur.org/cdi/english/, though I'll admit that there's quite some room for improvement... If you can tell us which missing and/or unclear parts you would really need to be improved, we can take a look at updating the documentation there.

All CDI drivers in the official repository use English identifiers, so it should be reasonably easy to make sense of them. Most are additionally commented in German, but some like ne2k or hdaudio are commented in English.
Developer of tyndur - community OS of Lowlevel (German)
User avatar
Lionel
Member
Member
Posts: 117
Joined: Fri Jul 16, 2010 2:16 pm
Libera.chat IRC: ryanel
Location: California

Re: CDI Drivers

Post by Lionel »

For the docs, you could use google translate
nevar
Posts: 12
Joined: Fri Feb 02, 2007 8:04 am

Re: CDI Drivers

Post by nevar »

Now i am using google translate but it only translates words not whole sentences and it sometimes get hard to understand as i am additionally not so good in english.

On Git repository there is something like this (in floppy driver):

Code: Select all

         // Pruefen ob der Kontroller bereit ist, Daten von uns zu akzeptieren
         if ((msr & (FLOPPY_MSR_RQM | FLOPPY_MSR_DIO)) == (FLOPPY_MSR_RQM)) {
             floppy_write_byte(device, FLOPPY_REG_DATA, data); 
             return 0; 
         }
So not all comment are in english. I think CDI (specyfication and drivers) could be more popular and understandable if it could have english comments.

I studied some drivers and "documentation" and it says:
Initialisation of drivers: The init() callback of each driver is called. ...
As i understand the system loads driver file into memory and runs its Init() function but in example floppy driver i don't see any Init().

There is floppy_driver_init(), it inits driver structure by:

Code: Select all

cdi_storage_driver_init(&floppy_driver);
but floppy_driver_init(); is in that structure:

Code: Select all

 static struct cdi_storage_driver floppy_driver = { 
     .drv = { 
         .type           = CDI_STORAGE, 
         .name           = DRIVER_NAME, 
         .init           = floppy_driver_init, 
         .destroy        = floppy_driver_destroy, 
         .remove_device  = floppy_remove_device, 
     }, 
     .read_blocks        = floppy_read_blocks, 
     .write_blocks       = floppy_write_blocks, 
 };
Questions are:
floppy_driver_init(), initiates driver and gives own address to initialization, what for ?
Is function Init() mentioned in documentation, in fact the function floppy_driver_init() ?
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: CDI Drivers

Post by Kevin »

nevar wrote:So not all comment are in english. I think CDI (specyfication and drivers) could be more popular and understandable if it could have english comments.
No doubt, it's just that someone has to do the translation (and in fact, even in German large parts of the higher level documenation are missing yet).

Code: Select all

 static struct cdi_storage_driver floppy_driver = { 
     .drv = { 
         .type           = CDI_STORAGE, 
         .name           = DRIVER_NAME, 
         .init           = floppy_driver_init, 
         .destroy        = floppy_driver_destroy, 
         .remove_device  = floppy_remove_device, 
     }, 
     .read_blocks        = floppy_read_blocks, 
     .write_blocks       = floppy_write_blocks, 
 };
Questions are:
floppy_driver_init(), initiates driver and gives own address to initialization, what for ?
Is function Init() mentioned in documentation, in fact the function floppy_driver_init() ?
Yes, init() is a function pointer in struct cdi_driver and for floppy it's assigned floppy_driver_init().

The idea is that the struct you quoted contains the whole externally visible interface. For example, for your OS to read something from the floppy, you would call floppy_driver->read_blocks(). This is the reason why it's CDI_DRIVER(floppy_driver) without any other parameters - the struct contains everything that you need to know in order to use the driver.
Developer of tyndur - community OS of Lowlevel (German)
nevar
Posts: 12
Joined: Fri Feb 02, 2007 8:04 am

Re: CDI Drivers

Post by nevar »

Thanks for clarifying this.
I need some more advice. I am wtiting my system in assembler and dont have too much experience in C programming. When I compile driver code I need to do some global export of structure cdi_storage_driver to use function floppy_driver_init().

I cannot link driver .o files with my system because I compile kernel to RDOFF file type. I must then search for driver structure location when loading driver file into memory, some sort of dynamic linking.
So I have to compile the driver code into object file to see this structure as ralocation entry or use some C directive global ?
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: CDI Drivers

Post by Kevin »

What you usually do is to create new ELF section that contains pointers to all driver structs in that object. In tyndur, the implementation looks like this:

Code: Select all

#define cdi_glue(x, y) x ## y
#define cdi_declare_driver(drv, counter) \
    static const void* __attribute__((section("cdi_drivers"), used)) \
        cdi_glue(__cdi_driver_, counter) = &drv;

#define CDI_DRIVER(name, drv, deps...) cdi_declare_driver(drv, __COUNTER__)
So you end up with a ELF section cdi_drivers that contains an array of pointers to the driver structs. Or in your case, with relocatables, you will actually see a relocation for each entry in the array.
Developer of tyndur - community OS of Lowlevel (German)
nevar
Posts: 12
Joined: Fri Feb 02, 2007 8:04 am

Re: CDI Drivers

Post by nevar »

Thank you Kevin for help.
I think for this point it is all I need to know to go ahead.

I must say that, CDI is very good specyfication for simple OS and I will try to implement it. But it realy needs to be more documented.
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: CDI Drivers

Post by Kevin »

Yeah, I know. And when people actually use the documentation, there is some motivation to write it. Maybe I can have a look this week after a long time.

Of course, patches are always welcome as well.
Developer of tyndur - community OS of Lowlevel (German)
nevar
Posts: 12
Joined: Fri Feb 02, 2007 8:04 am

Re: CDI Drivers

Post by nevar »

I have loaded in my system the floppy disk driver from CDI Git repository. But it hangs on Init() function. Does anyone has this driver working ?
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: CDI Drivers

Post by Kevin »

Guess it's called bitrot... Now we have the proof that noone is using floppies any more. ;)

With this patch it works for me again:

Code: Select all

diff --git a/floppy/main.c b/floppy/main.c
index c516a23..4e62e9f 100644
--- a/floppy/main.c
+++ b/floppy/main.c
@@ -68,7 +68,7 @@ static int floppy_driver_init(void)
 
         // Geraet nur eintragen wenn es existiert
         if (floppy_device_probe(device) != 0) {
-            floppy_init_device((struct cdi_device*) device);
+            device->dev.dev.driver = &floppy_driver.drv;
             cdi_list_push(floppy_driver.drv.devices, device);
         } else {
             free(device);
@@ -86,6 +86,10 @@ static int floppy_driver_init(void)
         return -1;
     }
 
+    for (i = 0; (device = cdi_list_get(floppy_driver.drv.devices, i)); i++) {
+        floppy_init_device(&device->dev.dev);
+    }
+
     return 0;
 }
Developer of tyndur - community OS of Lowlevel (German)
Post Reply