driver: add initial driver layer functions
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
b6c9e0a2ba
commit
6340e5d450
4 changed files with 40 additions and 3 deletions
|
|
@ -376,7 +376,7 @@ static void ahci_probe_ports(struct ahci_host *host)
|
|||
}
|
||||
}
|
||||
|
||||
static int ahci_init_device(struct pci_device *device, size_t ahci_dev_no)
|
||||
static int ahci_init_device(struct pci_device *device)
|
||||
{
|
||||
struct ahci_host *host = kzalloc(sizeof(struct ahci_host), ALLOC_KERN);
|
||||
if (!host)
|
||||
|
|
@ -395,6 +395,8 @@ void ahci_init()
|
|||
list_t dev_list;
|
||||
list_create(&dev_list);
|
||||
|
||||
driver_register("ahci", DRIVER_PCI, ahci_init_device, NULL, 1, 6);
|
||||
|
||||
krdy("AHCI ready\n");
|
||||
}
|
||||
DRIVER_ENTRY_PRIORITY(ahci_init, 3);
|
||||
DRIVER_ENTRY_PRIORITY(ahci_init, 2);
|
||||
|
|
|
|||
|
|
@ -152,4 +152,4 @@ void pci_init()
|
|||
|
||||
krdy("PCI ready\n");
|
||||
}
|
||||
DRIVER_ENTRY_PRIORITY(pci_init, 2);
|
||||
DRIVER_ENTRY_PRIORITY(pci_init, 4);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,26 @@
|
|||
#ifndef _DRIVER_H_
|
||||
#define _DRIVER_H_
|
||||
|
||||
#include <kernel/common.h>
|
||||
#include <drivers/pci.h>
|
||||
|
||||
#define DRIVER_ENTRY(fn) static void (*__initcall_##fn)(void) __attribute((used, section(".initcall"))) = fn
|
||||
#define DRIVER_ENTRY_PRIORITY(fn, pr) static void (*__initcall_##fn)(void) __attribute((used, section(".initcall." #pr))) = fn
|
||||
|
||||
#define DRIVER_PCI 1
|
||||
|
||||
typedef int (*pci_init_t)(struct pci_device *dev);
|
||||
|
||||
struct driver {
|
||||
char name[32];
|
||||
u64 type;
|
||||
void *init_device;
|
||||
void *deinit_device;
|
||||
u64 major;
|
||||
u64 minor;
|
||||
};
|
||||
|
||||
int driver_register(const char *name, u64 type, void *init, void *deinit, u64 major, u64 minor);
|
||||
struct driver *driver_find(const char *name);
|
||||
|
||||
#endif /* _DRIVER_H_ */
|
||||
|
|
|
|||
|
|
@ -1 +1,17 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
#include <kernel/driver.h>
|
||||
#include <kernel/slab.h>
|
||||
#include <lib/string.h>
|
||||
|
||||
int driver_register(const char *name, u64 type, void *init, void *deinit, u64 major, u64 minor)
|
||||
{
|
||||
struct driver *driver = kzalloc(sizeof(struct driver), ALLOC_KERN);
|
||||
strncpy(driver->name, name, sizeof(driver->name) - 1);
|
||||
driver->type = type;
|
||||
driver->init_device = init;
|
||||
driver->deinit_device = deinit;
|
||||
driver->major = major;
|
||||
driver->minor = minor;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue