Page 1 of 1
CDI Drivers
Posted: Sun Feb 26, 2012 11:22 am
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.
Re: CDI Drivers
Posted: Sun Feb 26, 2012 4:03 pm
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.
Re: CDI Drivers
Posted: Sun Feb 26, 2012 11:48 pm
by Lionel
For the docs, you could use google translate
Re: CDI Drivers
Posted: Mon Feb 27, 2012 2:32 am
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() ?
Re: CDI Drivers
Posted: Mon Feb 27, 2012 3:11 am
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.
Re: CDI Drivers
Posted: Mon Feb 27, 2012 3:44 am
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 ?
Re: CDI Drivers
Posted: Mon Feb 27, 2012 4:32 am
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.
Re: CDI Drivers
Posted: Mon Feb 27, 2012 5:17 am
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.
Re: CDI Drivers
Posted: Mon Feb 27, 2012 5:24 am
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.
Re: CDI Drivers
Posted: Sun Mar 04, 2012 4:53 pm
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 ?
Re: CDI Drivers
Posted: Mon Mar 05, 2012 4:07 am
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;
}