blob: be81ab95c41f1708cde6f445a06cce19ba31eff7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
/* Copyright (C) 2026 Richard Qin */
#pragma once
/*
* chardev.h — Character device abstraction
*
* Minimal Linux-style cdev registry: each character device has a
* major/minor number and a file_operations table.
*/
#include <lume/types.h>
#include <lume/list.h>
struct file_operations;
/* ================================================================== */
/* MKDEV / MAJOR / MINOR */
/* ================================================================== */
inline constexpr uint32 MKDEV(uint32 ma, uint32 mi) {
return (ma << 8) | (mi & 0xFF);
}
inline constexpr uint32 MAJOR(uint32 dev) { return dev >> 8; }
inline constexpr uint32 MINOR(uint32 dev) { return dev & 0xFF; }
/* ================================================================== */
/* cdev — character device descriptor */
/* ================================================================== */
struct cdev {
const char* name;
uint32 dev; /* MKDEV(major, minor) */
const file_operations* fops;
list_node list; /* global cdev list */
};
/* ================================================================== */
/* API */
/* ================================================================== */
void cdev_init();
void cdev_register(cdev* dev);
cdev* cdev_find(uint32 dev);
|