All checks were successful
Build documentation / build-and-deploy (push) Successful in 3m12s
43 lines
1.4 KiB
C
43 lines
1.4 KiB
C
#ifndef _KERNEL_DEVICE_DEVICE_H
|
|
#define _KERNEL_DEVICE_DEVICE_H
|
|
|
|
#include <libk/list.h>
|
|
#include <libk/rbtree.h>
|
|
#include <libk/std.h>
|
|
#include <proc/proc.h>
|
|
#include <proc/reschedule.h>
|
|
#include <sync/spin_lock.h>
|
|
#include <sys/smp.h>
|
|
|
|
#define device_op1(d, op, proc, rctx, a1, a2, a3, a4, ...) \
|
|
(d)->ops[(op)]((d), (proc), (rctx), (void*)(a1), (void*)(a2), (void*)(a3), (void*)(a4))
|
|
|
|
#define device_op(d, op, proc, rctx, ...) \
|
|
device_op1 (d, op, proc, rctx, __VA_ARGS__, NULL, NULL, NULL, NULL)
|
|
|
|
struct device;
|
|
|
|
typedef int (*device_op_func_t) (struct device* device, struct proc*, struct reschedule_ctx* rctx,
|
|
void* a1, void* a2, void* a3, void* a4);
|
|
|
|
typedef bool (*device_init_func_t) (struct device* device, void* arg);
|
|
typedef void (*device_fini_func_t) (struct device* device);
|
|
|
|
struct device {
|
|
int id;
|
|
device_op_func_t ops[32];
|
|
spin_lock_t lock;
|
|
struct rb_node_link device_tree_link;
|
|
device_init_func_t init;
|
|
device_fini_func_t fini;
|
|
void* udata;
|
|
};
|
|
|
|
struct device* device_create (int id, device_op_func_t* ops, size_t ops_len,
|
|
device_init_func_t init, device_fini_func_t fini, void* arg);
|
|
struct device* device_find (int id);
|
|
void device_delete (struct device* device);
|
|
void devices_init (void);
|
|
|
|
#endif // _KERNEL_DEVICE_DEVICE_H
|