opuntiaOS - an operating system targeting x86 and ARMv7
at master 2.1 kB view raw
1/* 2 * Copyright (C) 2020-2022 The opuntiaOS Project Authors. 3 * + Contributed by Nikita Melekhin <nimelehin@gmail.com> 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9#ifndef _KERNEL_DRIVERS_DRIVER_MANAGER_H 10#define _KERNEL_DRIVERS_DRIVER_MANAGER_H 11 12#include <drivers/bits/device.h> 13#include <drivers/bits/driver.h> 14#include <drivers/devtree.h> 15#include <libkern/types.h> 16 17#define MAX_DRIVERS_COUNT 256 18#define MAX_DEVICES_COUNT 64 19 20#define DEVMAN_FUNC_NOTIFY 0x0 21#define DEVMAN_FUNC_DEVICE_START 0x1 22#define DEVMAN_FUNC_DRIVER_START 0x1 23#define DEVMAN_FUNC_DRIVER_EMIT_DRIVER 0x1 24#define DEVMAN_FUNC_DRIVER_EMIT_DEVICE 0x2 25 26#define DEFAULT_DRIVER_PRIV (100) 27 28typedef void (*driver_installation_func_t)(); 29#define devman_register_driver_installation_order(func, N) \ 30 static driver_installation_func_t registered_driver_##func \ 31 __attribute__((used)) __attribute__((section(".driver_init_sections." #N))) \ 32 = func 33 34#define devman_register_driver_installation(func) devman_register_driver_installation_order(func, DEFAULT_DRIVER_PRIV) 35 36enum DEVMAN_NOTIFICATIONS { 37 DEVMAN_NOTIFICATION_DEVFS_READY = 0, 38 DEVMAN_NOTIFICATION_NEW_DRIVER = 1, 39 DEVMAN_NOTIFICATION_NEW_DEVICE = 2, 40 DEVMAN_NOTIFICATION_STOP, 41}; 42 43extern driver_t drivers[MAX_DRIVERS_COUNT]; 44extern device_t devices[MAX_DEVICES_COUNT]; 45 46int devman_init(); 47int devman_install_drivers(); 48void devman_run(); 49int devman_register_driver(driver_desc_t driver_info, const char* name); 50int devman_register_device(device_desc_t device_info, int type); 51device_t* new_virtual_device(int type); 52int devman_get_driver_id_by_name(); 53void devman_send_notification(uint32_t msg, uint32_t param); 54 55static inline void* devman_driver_function(int driver_id, int function_id) 56{ 57 return drivers[driver_id].desc.functions[function_id]; 58} 59 60static inline void* devman_function_handler(device_t* dev, int function_id) 61{ 62 return devman_driver_function(dev->driver_id, function_id); 63} 64 65#endif // _KERNEL_DRIVERS_DRIVER_MANAGER_H