Rework the bus drivers
This commit is contained in:
parent
bac9bd3bf2
commit
0f4f39e067
|
@ -4,19 +4,35 @@
|
|||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "bus.h"
|
||||
|
||||
|
||||
#if defined(__amd64__) || defined(__i386__)
|
||||
# include "bus/ioport.c"
|
||||
#endif
|
||||
|
||||
|
||||
/* bus_init */
|
||||
ukBus * bus_init(char const * name)
|
||||
ukBus * bus_init(ukBus * parent, char const * name)
|
||||
{
|
||||
if(strcmp(name, "ioport") == 0)
|
||||
return _ioport_bus_init();
|
||||
ukBus * drivers[] = {
|
||||
#if defined(__amd64__) || defined(__i386__)
|
||||
&ioport_bus
|
||||
#endif
|
||||
};
|
||||
size_t i;
|
||||
|
||||
for(i = 0; i < sizeof(drivers) / sizeof(*drivers); i++)
|
||||
if(strncmp(drivers[i]->name, name,
|
||||
strlen(drivers[i]->name)) == 0
|
||||
&& drivers[i]->init != NULL)
|
||||
{
|
||||
printf("%s%s%s\n", name, (parent != NULL) ? " at " : "",
|
||||
(parent != NULL) ? parent->name : "");
|
||||
return drivers[i]->init(parent);
|
||||
}
|
||||
errno = ENODEV;
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -17,7 +17,10 @@ typedef struct _ukBusData ukBusData;
|
|||
|
||||
struct _ukBus
|
||||
{
|
||||
ukBus * (*init)(void);
|
||||
char const name[16];
|
||||
|
||||
ukBus * (*init)(ukBus * bus);
|
||||
void (*destroy)(ukBus * bus);
|
||||
|
||||
int (*read8)(ukBus * bus, ukBusAddress address, uint8_t * value);
|
||||
int (*read16)(ukBus * bus, ukBusAddress address, uint16_t * value);
|
||||
|
@ -32,6 +35,6 @@ struct _ukBus
|
|||
|
||||
|
||||
/* prototypes */
|
||||
ukBus * bus_init(char const * name);
|
||||
ukBus * bus_init(ukBus * parent, char const * name);
|
||||
|
||||
#endif /* !UKERNEL_DRIVERS_BUS_H */
|
||||
|
|
|
@ -15,7 +15,7 @@ typedef struct _ukBus IOPortBus;
|
|||
|
||||
|
||||
/* prototypes */
|
||||
static IOPortBus * _ioport_bus_init(void);
|
||||
static IOPortBus * _ioport_bus_init(ukBus * parent);
|
||||
static int _ioport_bus_read8(IOPortBus * bus, ukBusAddress address,
|
||||
uint8_t * value);
|
||||
static int _ioport_bus_read16(IOPortBus * bus, ukBusAddress address,
|
||||
|
@ -31,9 +31,11 @@ static int _ioport_bus_write32(IOPortBus * bus, ukBusAddress address,
|
|||
|
||||
|
||||
/* variables */
|
||||
static IOPortBus _ioport_bus =
|
||||
IOPortBus ioport_bus =
|
||||
{
|
||||
"ioport",
|
||||
_ioport_bus_init,
|
||||
NULL,
|
||||
_ioport_bus_read8,
|
||||
_ioport_bus_read16,
|
||||
_ioport_bus_read32,
|
||||
|
@ -48,9 +50,11 @@ static IOPortBus _ioport_bus =
|
|||
/* functions */
|
||||
/* bus */
|
||||
/* ioport_bus_init */
|
||||
static IOPortBus * _ioport_bus_init(void)
|
||||
static IOPortBus * _ioport_bus_init(ukBus * parent)
|
||||
{
|
||||
return &_ioport_bus;
|
||||
(void) parent;
|
||||
|
||||
return &ioport_bus;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ typedef struct _ukBus TTYBus;
|
|||
|
||||
|
||||
/* prototypes */
|
||||
static TTYBus * _tty_bus_init(void);
|
||||
static TTYBus * _tty_bus_init(ukBus * parent);
|
||||
|
||||
static int _tty_bus_read8(TTYBus * bus, ukBusAddress address,
|
||||
uint8_t * value);
|
||||
|
@ -35,9 +35,11 @@ extern int _write(int fildes, void const * buf, size_t count);
|
|||
|
||||
|
||||
/* variables */
|
||||
static TTYBus _tty_bus =
|
||||
TTYBus tty_bus =
|
||||
{
|
||||
"tty",
|
||||
_tty_bus_init,
|
||||
NULL,
|
||||
_tty_bus_read8,
|
||||
_tty_bus_read16,
|
||||
_tty_bus_read32,
|
||||
|
@ -52,9 +54,11 @@ static TTYBus _tty_bus =
|
|||
/* functions */
|
||||
/* bus */
|
||||
/* tty_bus_init */
|
||||
static TTYBus * _tty_bus_init(void)
|
||||
static TTYBus * _tty_bus_init(ukBus * parent)
|
||||
{
|
||||
return &_tty_bus;
|
||||
(void) parent;
|
||||
|
||||
return &tty_bus;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -42,8 +42,8 @@ int multiboot(ukMultibootInfo * mi)
|
|||
size_t i;
|
||||
ukMultibootMod * mod;
|
||||
|
||||
/* initialize the root bus */
|
||||
bus = bus_init(LOADER_BUS);
|
||||
/* initialize the main bus */
|
||||
bus = bus_init(NULL, LOADER_BUS);
|
||||
|
||||
#ifdef notyet
|
||||
/* detect the video driver to use */
|
||||
|
|
|
@ -50,8 +50,8 @@ int multiboot(const ukMultibootInfo * mi)
|
|||
|
||||
memcpy(&kmi, mi, sizeof(kmi));
|
||||
|
||||
/* initialize the root bus */
|
||||
bus = bus_init(LOADER_BUS);
|
||||
/* initialize the main bus */
|
||||
bus = bus_init(NULL, LOADER_BUS);
|
||||
|
||||
#ifdef notyet
|
||||
/* detect the video driver to use */
|
||||
|
|
|
@ -11,10 +11,12 @@
|
|||
|
||||
|
||||
/* bus_init */
|
||||
ukBus * bus_init(char const * name)
|
||||
ukBus * bus_init(ukBus * parent, char const * name)
|
||||
{
|
||||
if(strcmp(name, "tty") == 0)
|
||||
return _tty_bus_init();
|
||||
char tty[] = "tty";
|
||||
|
||||
if(strncmp(name, tty, sizeof(tty) - 1) == 0)
|
||||
return tty_bus.init(parent);
|
||||
errno = ENODEV;
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user