Squash commits for public release
This commit is contained in:
68
kernel/include/drivers/bits/device.h
Normal file
68
kernel/include/drivers/bits/device.h
Normal file
@@ -0,0 +1,68 @@
|
||||
#ifndef _KERNEL_DRIVERS_BITS_DEVICE_H
|
||||
#define _KERNEL_DRIVERS_BITS_DEVICE_H
|
||||
|
||||
#include <libkern/lock.h>
|
||||
#include <libkern/types.h>
|
||||
|
||||
enum DEVICES_TYPE {
|
||||
DEVICE_STORAGE = (1 << 0),
|
||||
DEVICE_SOUND = (1 << 1),
|
||||
DEVICE_INPUT_SYSTEMS = (1 << 2),
|
||||
DEVICE_NETWORK = (1 << 3),
|
||||
DEVICE_DISPLAY = (1 << 4),
|
||||
DEVICE_BUS_CONTROLLER = (1 << 5),
|
||||
DEVICE_BRIDGE = (1 << 6),
|
||||
DEVICE_CHAR = (1 << 7),
|
||||
DEVICE_RTC = (1 << 8),
|
||||
DEVICE_UNKNOWN = (1 << 9),
|
||||
};
|
||||
|
||||
enum DEVICE_DESC_TYPE {
|
||||
DEVICE_DESC_PCI,
|
||||
DEVICE_DESC_DEVTREE,
|
||||
};
|
||||
|
||||
struct device_desc_pci {
|
||||
uint8_t bus;
|
||||
uint8_t device;
|
||||
uint8_t function;
|
||||
uint16_t vendor_id;
|
||||
uint16_t device_id;
|
||||
uint8_t class_id;
|
||||
uint8_t subclass_id;
|
||||
uint8_t interface_id;
|
||||
uint8_t revision_id;
|
||||
uint32_t interrupt;
|
||||
uint32_t port_base;
|
||||
};
|
||||
typedef struct device_desc_pci device_desc_pci_t;
|
||||
|
||||
struct devtree_entry;
|
||||
struct device_desc_devtree {
|
||||
struct devtree_entry* entry;
|
||||
};
|
||||
typedef struct device_desc_devtree device_desc_devtree_t;
|
||||
|
||||
struct device_desc {
|
||||
int type;
|
||||
union {
|
||||
device_desc_pci_t pci;
|
||||
device_desc_devtree_t devtree;
|
||||
};
|
||||
uint32_t args[4];
|
||||
};
|
||||
typedef struct device_desc device_desc_t;
|
||||
|
||||
#define DRIVER_ID_EMPTY (0xff)
|
||||
struct device {
|
||||
int id;
|
||||
int type;
|
||||
bool is_virtual;
|
||||
int driver_id;
|
||||
|
||||
spinlock_t lock;
|
||||
device_desc_t device_desc;
|
||||
};
|
||||
typedef struct device device_t;
|
||||
|
||||
#endif // _KERNEL_DRIVERS_BITS_DEVICE_H
|
||||
123
kernel/include/drivers/bits/driver.h
Normal file
123
kernel/include/drivers/bits/driver.h
Normal file
@@ -0,0 +1,123 @@
|
||||
#ifndef _KERNEL_DRIVERS_BITS_DRIVER_H
|
||||
#define _KERNEL_DRIVERS_BITS_DRIVER_H
|
||||
|
||||
#include <libkern/types.h>
|
||||
|
||||
#define MAX_DRIVER_FUNCTION_COUNT 32
|
||||
|
||||
// Supported driver's types
|
||||
enum DRIVERS_TYPE {
|
||||
DRIVER_STORAGE_DEVICE = (1 << 0),
|
||||
DRIVER_VIDEO_DEVICE = (1 << 1),
|
||||
DRIVER_SOUND_DEVICE = (1 << 2),
|
||||
DRIVER_INPUT_SYSTEMS_DEVICE = (1 << 3),
|
||||
DRIVER_NETWORK_DEVICE = (1 << 4),
|
||||
DRIVER_BUS_CONTROLLER = (1 << 5),
|
||||
DRIVER_CHAR_DEVICE = (1 << 6),
|
||||
DRIVER_VIRTUAL_FILE_SYSTEM = (1 << 7),
|
||||
DRIVER_FILE_SYSTEM = (1 << 8),
|
||||
DRIVER_TIMER = (1 << 9),
|
||||
DRIVER_RTC = (1 << 10),
|
||||
DRIVER_TIME_MANAGER = (1 << 11),
|
||||
DRIVER_VIRTUAL = (1 << 12),
|
||||
};
|
||||
|
||||
// Api function of DRIVER_STORAGE type
|
||||
enum DRIVER_VIDEO_OPERTAION {
|
||||
DRIVER_VIDEO_INIT = 0x1, // function called when a device is found
|
||||
DRIVER_VIDEO_SET_RESOLUTION,
|
||||
};
|
||||
|
||||
// Api function of DRIVER_STORAGE type
|
||||
enum DRIVER_STORAGE_OPERTAION {
|
||||
DRIVER_STORAGE_ADD_DEVICE = 0x1, // function called when a device is found
|
||||
DRIVER_STORAGE_READ,
|
||||
DRIVER_STORAGE_WRITE,
|
||||
DRIVER_STORAGE_FLUSH,
|
||||
DRIVER_STORAGE_CAPACITY,
|
||||
};
|
||||
|
||||
// Api function of DRIVER_INPUT_SYSTEMS type
|
||||
enum DRIVER_INPUT_SYSTEMS_OPERTAION {
|
||||
DRIVER_INPUT_SYSTEMS_ADD_DEVICE = 0x1, // function called when a device is found
|
||||
DRIVER_INPUT_SYSTEMS_GET_LAST_KEY,
|
||||
DRIVER_INPUT_SYSTEMS_DISCARD_LAST_KEY
|
||||
};
|
||||
|
||||
// Api function of DRIVER_CONTROLLER type
|
||||
enum DRIVER_BUS_CONTROLLER_OPERTAION {
|
||||
DRIVER_BUS_CONTROLLER_FIND_DEVICE = 0x1, // function called when a device is found
|
||||
};
|
||||
|
||||
// Api function of DRIVER_VIRTUAL_FILE_SYSTEM type
|
||||
enum DRIVER_VIRTUAL_FILE_SYSTEM_OPERTAION {
|
||||
DRIVER_VIRTUAL_FILE_SYSTEM_ADD_DRIVER = 0x1,
|
||||
DRIVER_VIRTUAL_FILE_SYSTEM_ADD_DEVICE,
|
||||
DRIVER_VIRTUAL_FILE_SYSTEM_EJECT_DEVICE,
|
||||
};
|
||||
|
||||
// Api function of DRIVER_FILE_SYSTEM type
|
||||
enum DRIVER_FILE_SYSTEM_OPERTAION {
|
||||
DRIVER_FILE_SYSTEM_RECOGNIZE = 0x1,
|
||||
DRIVER_FILE_SYSTEM_PREPARE_FS,
|
||||
DRIVER_FILE_SYSTEM_EJECT_DEVICE,
|
||||
|
||||
DRIVER_FILE_SYSTEM_OPEN,
|
||||
DRIVER_FILE_SYSTEM_CAN_READ,
|
||||
DRIVER_FILE_SYSTEM_CAN_WRITE,
|
||||
DRIVER_FILE_SYSTEM_READ,
|
||||
DRIVER_FILE_SYSTEM_WRITE,
|
||||
DRIVER_FILE_SYSTEM_TRUNCATE,
|
||||
DRIVER_FILE_SYSTEM_MKDIR,
|
||||
DRIVER_FILE_SYSTEM_RMDIR,
|
||||
|
||||
DRIVER_FILE_SYSTEM_READ_INODE,
|
||||
DRIVER_FILE_SYSTEM_WRITE_INODE,
|
||||
DRIVER_FILE_SYSTEM_FREE_INODE,
|
||||
DRIVER_FILE_SYSTEM_LOOKUP,
|
||||
DRIVER_FILE_SYSTEM_GETDENTS,
|
||||
DRIVER_FILE_SYSTEM_CREATE,
|
||||
DRIVER_FILE_SYSTEM_UNLINK,
|
||||
|
||||
DRIVER_FILE_SYSTEM_FSTAT,
|
||||
DRIVER_FILE_SYSTEM_FCHMOD,
|
||||
DRIVER_FILE_SYSTEM_IOCTL,
|
||||
DRIVER_FILE_SYSTEM_MMAP,
|
||||
};
|
||||
|
||||
enum DRIVER_RTC_OPERTAION {
|
||||
DRIVER_RTC_GET_TIME,
|
||||
};
|
||||
|
||||
struct driver;
|
||||
struct device;
|
||||
typedef struct {
|
||||
void (*recieve_notification)(uintptr_t key, uintptr_t val);
|
||||
int (*on_start)();
|
||||
int (*on_stop)();
|
||||
int (*init_with_dev)(struct device* device);
|
||||
} driver_system_funcs_t;
|
||||
|
||||
enum DRIVER_DESC_FLAGS {
|
||||
DRIVER_DESC_FLAG_START = (1 << 0),
|
||||
};
|
||||
|
||||
struct driver_desc {
|
||||
int type;
|
||||
uint32_t flags;
|
||||
uint32_t listened_device_mask;
|
||||
uint32_t listened_driver_mask;
|
||||
void* functions[MAX_DRIVER_FUNCTION_COUNT];
|
||||
driver_system_funcs_t system_funcs;
|
||||
};
|
||||
typedef struct driver_desc driver_desc_t;
|
||||
|
||||
struct driver {
|
||||
int id;
|
||||
int status;
|
||||
driver_desc_t desc;
|
||||
const char* name;
|
||||
};
|
||||
typedef struct driver driver_t;
|
||||
|
||||
#endif // _KERNEL_DRIVERS_BITS_DRIVER_H
|
||||
10
kernel/include/drivers/bus/x86/ide.h
Normal file
10
kernel/include/drivers/bus/x86/ide.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef _KERNEL_DRIVERS_BUS_X86_IDE_H
|
||||
#define _KERNEL_DRIVERS_BUS_X86_IDE_H
|
||||
|
||||
#include <drivers/driver_manager.h>
|
||||
#include <libkern/types.h>
|
||||
|
||||
void ide_install();
|
||||
int ide_init_with_dev(device_t* dev);
|
||||
|
||||
#endif // _KERNEL_DRIVERS_BUS_X86_IDE_H
|
||||
46
kernel/include/drivers/bus/x86/pci.h
Normal file
46
kernel/include/drivers/bus/x86/pci.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef _KERNEL_DRIVERS_BUS_X86_PCI_H
|
||||
#define _KERNEL_DRIVERS_BUS_X86_PCI_H
|
||||
|
||||
#include <drivers/driver_manager.h>
|
||||
#include <libkern/c_attrs.h>
|
||||
#include <libkern/types.h>
|
||||
#include <platform/x86/port.h>
|
||||
|
||||
struct PACKED pcidd {
|
||||
uint8_t bus;
|
||||
uint8_t device;
|
||||
uint8_t function;
|
||||
|
||||
uint16_t vendor_id;
|
||||
uint16_t device_id;
|
||||
|
||||
uint8_t class_id;
|
||||
uint8_t subclass_id;
|
||||
uint8_t interface_id;
|
||||
uint8_t revision_id;
|
||||
|
||||
uint32_t interrupt;
|
||||
uint32_t port_base;
|
||||
};
|
||||
typedef struct pcidd pcidd_t;
|
||||
|
||||
enum bar_type {
|
||||
MEMORY_MAPPED = 0,
|
||||
INPUT_OUTPUT = 1
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
char prefetchable;
|
||||
uint32_t address;
|
||||
uint8_t type;
|
||||
} bar_t;
|
||||
|
||||
void pci_install();
|
||||
uint32_t pci_read(uint16_t bus, uint16_t device, uint16_t function, uint32_t offset);
|
||||
void pci_write(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset, uint32_t data);
|
||||
char pci_has_device_functions(uint8_t bus, uint8_t device);
|
||||
int pci_find_devices();
|
||||
device_desc_t pci_get_device_desriptor(uint8_t bus, uint8_t device, uint8_t function);
|
||||
uint32_t pci_read_bar(device_t* dev, int bar_id);
|
||||
|
||||
#endif /* _KERNEL_DRIVERS_BUS_X86_PCI_H */
|
||||
21
kernel/include/drivers/clock/arm/pl031.h
Normal file
21
kernel/include/drivers/clock/arm/pl031.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef _KERNEL_DRIVERS_CLOCK_ARM_PL031_H
|
||||
#define _KERNEL_DRIVERS_CLOCK_ARM_PL031_H
|
||||
|
||||
#include <drivers/driver_manager.h>
|
||||
#include <libkern/mask.h>
|
||||
#include <libkern/types.h>
|
||||
#include <platform/arm32/interrupts.h>
|
||||
#include <platform/arm32/target/cortex-a15/device_settings.h>
|
||||
|
||||
struct pl031_registers {
|
||||
uint32_t data;
|
||||
uint32_t match;
|
||||
uint32_t load;
|
||||
uint32_t control;
|
||||
// TO BE CONTINUED
|
||||
};
|
||||
typedef struct pl031_registers pl031_registers_t;
|
||||
|
||||
uint32_t pl031_read_rtc();
|
||||
|
||||
#endif // _KERNEL_DRIVERS_CLOCK_ARM_PL031_H
|
||||
8
kernel/include/drivers/clock/x86/rtc.h
Normal file
8
kernel/include/drivers/clock/x86/rtc.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _KERNEL_DRIVERS_CLOCK_X86_RTC_H
|
||||
#define _KERNEL_DRIVERS_CLOCK_X86_RTC_H
|
||||
|
||||
#include <libkern/types.h>
|
||||
|
||||
uint32_t rtc_load_time();
|
||||
|
||||
#endif /* _KERNEL_DRIVERS_CLOCK_X86_RTC_H */
|
||||
10
kernel/include/drivers/debug/screen.h
Normal file
10
kernel/include/drivers/debug/screen.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef _KERNEL_DRIVERS_DEBUG_SCREEN_H
|
||||
#define _KERNEL_DRIVERS_DEBUG_SCREEN_H
|
||||
|
||||
#include <libkern/types.h>
|
||||
|
||||
struct boot_args;
|
||||
int screen_setup(struct boot_args* boot_args);
|
||||
int screen_put_char(char c);
|
||||
|
||||
#endif //_KERNEL_DRIVERS_DEBUG_SCREEN_H
|
||||
51
kernel/include/drivers/devtree.h
Normal file
51
kernel/include/drivers/devtree.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef _KERNEL_DRIVERS_DEVTREE_H
|
||||
#define _KERNEL_DRIVERS_DEVTREE_H
|
||||
|
||||
#include <libkern/c_attrs.h>
|
||||
#include <libkern/types.h>
|
||||
#include <mem/boot.h>
|
||||
|
||||
#define DEVTREE_HEADER_SIGNATURE ("odtr3")
|
||||
#define DEVTREE_HEADER_SIGNATURE_LEN (sizeof(DEVTREE_HEADER_SIGNATURE) - 1)
|
||||
|
||||
struct PACKED devtree_header {
|
||||
char signature[8];
|
||||
uint32_t revision;
|
||||
uint32_t flags;
|
||||
uint32_t entries_count;
|
||||
uint32_t name_list_offset;
|
||||
};
|
||||
typedef struct devtree_header devtree_header_t;
|
||||
|
||||
#define DEVTREE_ENTRY_FLAGS_MMIO = (1 << 0)
|
||||
#define DEVTREE_ENTRY_TYPE_IO (0)
|
||||
#define DEVTREE_ENTRY_TYPE_FB (1)
|
||||
#define DEVTREE_ENTRY_TYPE_UART (2)
|
||||
#define DEVTREE_ENTRY_TYPE_RAM (3)
|
||||
#define DEVTREE_ENTRY_TYPE_STORAGE (4)
|
||||
#define DEVTREE_ENTRY_TYPE_BUS_CONTROLLER (5)
|
||||
#define DEVTREE_ENTRY_TYPE_RTC (6)
|
||||
|
||||
struct PACKED devtree_entry {
|
||||
uint32_t type;
|
||||
uint32_t flags;
|
||||
uint64_t region_base;
|
||||
uint64_t region_size;
|
||||
uint32_t irq_lane;
|
||||
uint32_t irq_flags;
|
||||
uint32_t irq_priority;
|
||||
uint32_t rel_name_offset;
|
||||
uint64_t aux1;
|
||||
uint64_t aux2;
|
||||
uint64_t aux3;
|
||||
uint64_t aux4;
|
||||
};
|
||||
typedef struct devtree_entry devtree_entry_t;
|
||||
|
||||
int devtree_init(boot_args_t* boot_args);
|
||||
devtree_entry_t* devtree_find_device(const char* name);
|
||||
const char* devtree_name_of_entry(devtree_entry_t* en);
|
||||
devtree_entry_t* devtree_new_entry(const devtree_entry_t* from);
|
||||
uint32_t devtree_new_entry_name(const char* ptr);
|
||||
|
||||
#endif // _KERNEL_DRIVERS_DEVTREE_H
|
||||
57
kernel/include/drivers/driver_manager.h
Normal file
57
kernel/include/drivers/driver_manager.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#ifndef _KERNEL_DRIVERS_DRIVER_MANAGER_H
|
||||
#define _KERNEL_DRIVERS_DRIVER_MANAGER_H
|
||||
|
||||
#include <drivers/bits/device.h>
|
||||
#include <drivers/bits/driver.h>
|
||||
#include <drivers/devtree.h>
|
||||
#include <libkern/types.h>
|
||||
|
||||
#define MAX_DRIVERS_COUNT 256
|
||||
#define MAX_DEVICES_COUNT 64
|
||||
|
||||
#define DEVMAN_FUNC_NOTIFY 0x0
|
||||
#define DEVMAN_FUNC_DEVICE_START 0x1
|
||||
#define DEVMAN_FUNC_DRIVER_START 0x1
|
||||
#define DEVMAN_FUNC_DRIVER_EMIT_DRIVER 0x1
|
||||
#define DEVMAN_FUNC_DRIVER_EMIT_DEVICE 0x2
|
||||
|
||||
#define DEFAULT_DRIVER_PRIV (100)
|
||||
|
||||
typedef void (*driver_installation_func_t)();
|
||||
#define devman_register_driver_installation_order(func, N) \
|
||||
static driver_installation_func_t registered_driver_##func \
|
||||
__attribute__((used)) __attribute__((section(".driver_init_sections." #N))) \
|
||||
= func
|
||||
|
||||
#define devman_register_driver_installation(func) devman_register_driver_installation_order(func, DEFAULT_DRIVER_PRIV)
|
||||
|
||||
enum DEVMAN_NOTIFICATIONS {
|
||||
DEVMAN_NOTIFICATION_DEVFS_READY = 0,
|
||||
DEVMAN_NOTIFICATION_NEW_DRIVER = 1,
|
||||
DEVMAN_NOTIFICATION_NEW_DEVICE = 2,
|
||||
DEVMAN_NOTIFICATION_STOP,
|
||||
};
|
||||
|
||||
extern driver_t drivers[MAX_DRIVERS_COUNT];
|
||||
extern device_t devices[MAX_DEVICES_COUNT];
|
||||
|
||||
int devman_init();
|
||||
int devman_install_drivers();
|
||||
void devman_run();
|
||||
int devman_register_driver(driver_desc_t driver_info, const char* name);
|
||||
int devman_register_device(device_desc_t device_info, int type);
|
||||
device_t* new_virtual_device(int type);
|
||||
int devman_get_driver_id_by_name(const char* name);
|
||||
void devman_send_notification(uintptr_t msg, uintptr_t param);
|
||||
|
||||
static inline void* devman_driver_function(int driver_id, int function_id)
|
||||
{
|
||||
return drivers[driver_id].desc.functions[function_id];
|
||||
}
|
||||
|
||||
static inline void* devman_function_handler(device_t* dev, int function_id)
|
||||
{
|
||||
return devman_driver_function(dev->driver_id, function_id);
|
||||
}
|
||||
|
||||
#endif // _KERNEL_DRIVERS_DRIVER_MANAGER_H
|
||||
49
kernel/include/drivers/graphics/arm/pl111.h
Normal file
49
kernel/include/drivers/graphics/arm/pl111.h
Normal file
@@ -0,0 +1,49 @@
|
||||
#ifndef _KERNEL_DRIVERS_GRAPHICS_ARM_PL111_H
|
||||
#define _KERNEL_DRIVERS_GRAPHICS_ARM_PL111_H
|
||||
|
||||
#include <drivers/driver_manager.h>
|
||||
#include <libkern/mask.h>
|
||||
#include <libkern/types.h>
|
||||
|
||||
enum PL111RegisterMasks {
|
||||
MASKDEFINE(PIXELS_PER_LINE, 2, 6),
|
||||
MASKDEFINE(LINES_PER_PANEL, 0, 10),
|
||||
|
||||
MASKDEFINE(LCD_POWER, 11, 1),
|
||||
MASKDEFINE(LCD_ENDIAN, 9, 2),
|
||||
MASKDEFINE(LCD_BGR, 8, 1),
|
||||
MASKDEFINE(LCD_DUAL, 7, 1),
|
||||
MASKDEFINE(LCD_TFT, 5, 1),
|
||||
MASKDEFINE(LCD_BW, 4, 1),
|
||||
MASKDEFINE(LCD_BPP, 1, 3),
|
||||
MASKDEFINE(LCD_EN, 0, 1),
|
||||
};
|
||||
|
||||
enum PL111Consts {
|
||||
NUM_TIMINGS = 4,
|
||||
NUM_PALETTE_WORDS = 0x378,
|
||||
LCD_16_BPP = 4, // Register constant for 16 bits per pixel
|
||||
LCD_24_BPP = 5, // Register constant for 24 bits per pixel
|
||||
};
|
||||
|
||||
struct pl111_registers {
|
||||
uint32_t lcd_timing_0;
|
||||
uint32_t lcd_timing_1;
|
||||
uint32_t lcd_timing_2;
|
||||
uint32_t lcd_timing_3;
|
||||
uint32_t lcd_upbase;
|
||||
uint32_t lcd_lpbase;
|
||||
uint32_t lcd_control;
|
||||
uint32_t lcd_imsc;
|
||||
uint32_t lcd_ris;
|
||||
uint32_t lcd_mis;
|
||||
uint32_t lcd_icr;
|
||||
uint32_t lcd_upcurr;
|
||||
uint32_t lcd_lpcurr;
|
||||
// TO BE CONTINUED
|
||||
};
|
||||
typedef struct pl111_registers pl111_registers_t;
|
||||
|
||||
void pl111_install();
|
||||
|
||||
#endif //_KERNEL_DRIVERS_GRAPHICS_ARM_PL111_H
|
||||
182
kernel/include/drivers/graphics/virtio_gpu.h
Normal file
182
kernel/include/drivers/graphics/virtio_gpu.h
Normal file
@@ -0,0 +1,182 @@
|
||||
#ifndef _KERNEL_DRIVERS_GRAPHICS_VIRTIO_GPU_H
|
||||
#define _KERNEL_DRIVERS_GRAPHICS_VIRTIO_GPU_H
|
||||
|
||||
#include <drivers/driver_manager.h>
|
||||
#include <drivers/virtio/virtio.h>
|
||||
#include <libkern/types.h>
|
||||
#include <mem/kmalloc.h>
|
||||
|
||||
enum CtrlType {
|
||||
// 2d commands
|
||||
CmdGetDisplayInfo = 0x0100,
|
||||
CmdResourceCreate2d,
|
||||
CmdResourceUref,
|
||||
CmdSetScanout,
|
||||
CmdResourceFlush,
|
||||
CmdTransferToHost2d,
|
||||
CmdResourceAttachBacking,
|
||||
CmdResourceDetachBacking,
|
||||
CmdGetCapsetInfo,
|
||||
CmdGetCapset,
|
||||
CmdGetEdid,
|
||||
// cursor commands
|
||||
CmdUpdateCursor = 0x0300,
|
||||
CmdMoveCursor,
|
||||
// success responses
|
||||
RespOkNoData = 0x1100,
|
||||
RespOkDisplayInfo,
|
||||
RespOkCapsetInfo,
|
||||
RespOkCapset,
|
||||
RespOkEdid,
|
||||
// error responses
|
||||
RespErrUnspec = 0x1200,
|
||||
RespErrOutOfMemory,
|
||||
RespErrInvalidScanoutId,
|
||||
RespErrInvalidResourceId,
|
||||
RespErrInvalidContextId,
|
||||
RespErrInvalidParameter,
|
||||
};
|
||||
|
||||
struct gpu_dev {
|
||||
virtio_queue_desc_t queue_desc;
|
||||
volatile virtio_mmio_registers_t* registers;
|
||||
uint32_t idx;
|
||||
uint32_t ack_used_idx;
|
||||
virtio_buffer_desc_t fb_desc;
|
||||
size_t width;
|
||||
size_t height;
|
||||
int current_fb;
|
||||
};
|
||||
typedef struct gpu_dev gpu_dev_t;
|
||||
|
||||
struct gpu_ctrl_header {
|
||||
uint32_t ctrl_type;
|
||||
uint32_t flags;
|
||||
uint64_t fence_id;
|
||||
uint32_t ctx_id;
|
||||
uint32_t padding;
|
||||
};
|
||||
typedef struct gpu_ctrl_header gpu_ctrl_header_t;
|
||||
|
||||
struct gpu_rect {
|
||||
uint32_t x;
|
||||
uint32_t y;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
};
|
||||
typedef struct gpu_rect gpu_rect_t;
|
||||
|
||||
struct gpu_display_one {
|
||||
gpu_rect_t r;
|
||||
uint32_t enabled;
|
||||
uint32_t flags;
|
||||
};
|
||||
typedef struct gpu_display_one gpu_display_one_t;
|
||||
|
||||
#define MAX_SCANOUTS (16)
|
||||
typedef struct gpu_resp_display_info {
|
||||
gpu_ctrl_header_t hdr;
|
||||
gpu_display_one_t pmodes[MAX_SCANOUTS];
|
||||
} gpu_resp_display_info_t;
|
||||
|
||||
typedef struct gpu_get_edid {
|
||||
gpu_ctrl_header_t hdr;
|
||||
uint32_t scanout;
|
||||
uint32_t padding;
|
||||
} gpu_get_edid_t;
|
||||
|
||||
typedef struct gpu_resp_edid {
|
||||
gpu_ctrl_header_t hdr;
|
||||
uint32_t size;
|
||||
uint32_t padding;
|
||||
uint8_t edid[1024];
|
||||
} gpu_resp_edid_t;
|
||||
|
||||
typedef enum gpu_formats {
|
||||
GPU_FORMAT_B8G8R8A8Unorm = 1,
|
||||
GPU_FORMAT_B8G8R8X8Unorm = 2,
|
||||
GPU_FORMAT_A8R8G8B8Unorm = 3,
|
||||
GPU_FORMAT_X8R8G8B8Unorm = 4,
|
||||
GPU_FORMAT_R8G8B8A8Unorm = 67,
|
||||
GPU_FORMAT_X8B8G8R8Unorm = 68,
|
||||
GPU_FORMAT_A8B8G8R8Unorm = 121,
|
||||
GPU_FORMAT_R8G8B8X8Unorm = 134,
|
||||
} gpu_formats_t;
|
||||
|
||||
typedef struct gpu_resource_create_2d {
|
||||
gpu_ctrl_header_t hdr;
|
||||
uint32_t resource_id;
|
||||
gpu_formats_t format;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
} gpu_resource_create_2d_t;
|
||||
|
||||
typedef struct gpu_resource_unref {
|
||||
gpu_ctrl_header_t hdr;
|
||||
uint32_t resource_id;
|
||||
uint32_t padding;
|
||||
} gpu_resource_unref_t;
|
||||
|
||||
typedef struct gpu_set_scanout {
|
||||
gpu_ctrl_header_t hdr;
|
||||
gpu_rect_t r;
|
||||
uint32_t scanout_id;
|
||||
uint32_t resource_id;
|
||||
} gpu_set_scanout_t;
|
||||
|
||||
typedef struct gpu_resource_flush {
|
||||
gpu_ctrl_header_t hdr;
|
||||
gpu_rect_t r;
|
||||
uint32_t resource_id;
|
||||
uint32_t padding;
|
||||
} gpu_resource_flush_t;
|
||||
|
||||
typedef struct gpu_transfer_to_host_2d {
|
||||
gpu_ctrl_header_t hdr;
|
||||
gpu_rect_t r;
|
||||
uint64_t offset;
|
||||
uint32_t resource_id;
|
||||
uint32_t padding;
|
||||
} gpu_transfer_to_host_2d_t;
|
||||
|
||||
typedef struct gpu_attach_backing {
|
||||
gpu_ctrl_header_t hdr;
|
||||
uint32_t resource_id;
|
||||
uint32_t nr_entries;
|
||||
} gpu_attach_backing_t;
|
||||
|
||||
typedef struct gpu_mem_entry {
|
||||
uint64_t addr;
|
||||
uint32_t length;
|
||||
uint32_t padding;
|
||||
} gpu_mem_entry_t;
|
||||
|
||||
typedef struct gpu_detach_backing {
|
||||
gpu_ctrl_header_t hdr;
|
||||
uint32_t resource_id;
|
||||
uint32_t padding;
|
||||
} gpu_detach_backing_t;
|
||||
|
||||
typedef struct gpu_cursor_pos {
|
||||
uint32_t scanout_id;
|
||||
uint32_t x;
|
||||
uint32_t y;
|
||||
uint32_t padding;
|
||||
} gpu_cursor_pos_t;
|
||||
|
||||
typedef struct gpu_update_cursor {
|
||||
gpu_ctrl_header_t hdr;
|
||||
gpu_cursor_pos_t pos;
|
||||
uint32_t resource_id;
|
||||
uint32_t hot_x;
|
||||
uint32_t hot_y;
|
||||
uint32_t padding;
|
||||
} gpu_update_cursor_t;
|
||||
|
||||
typedef struct gpu_request {
|
||||
void* request;
|
||||
void* response;
|
||||
void* alloc_start;
|
||||
} gpu_request_t;
|
||||
|
||||
#endif //_KERNEL_DRIVERS_GRAPHICS_VIRTIO_GPU_H
|
||||
12
kernel/include/drivers/graphics/x86/bga.h
Normal file
12
kernel/include/drivers/graphics/x86/bga.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef _KERNEL_DRIVERS_GRAPHICS_X86_BGA_H
|
||||
#define _KERNEL_DRIVERS_GRAPHICS_X86_BGA_H
|
||||
|
||||
#include <drivers/driver_manager.h>
|
||||
#include <libkern/types.h>
|
||||
#include <mem/kmalloc.h>
|
||||
#include <platform/x86/port.h>
|
||||
|
||||
void bga_install();
|
||||
int bga_init_with_dev(device_t* dev);
|
||||
|
||||
#endif //_KERNEL_DRIVERS_GRAPHICS_X86_BGA_H
|
||||
20
kernel/include/drivers/io/arm/pl050.h
Normal file
20
kernel/include/drivers/io/arm/pl050.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef _KERNEL_DRIVERS_IO_ARM_PL050_H
|
||||
#define _KERNEL_DRIVERS_IO_ARM_PL050_H
|
||||
|
||||
#include <drivers/driver_manager.h>
|
||||
#include <libkern/mask.h>
|
||||
#include <libkern/types.h>
|
||||
|
||||
struct pl050_registers {
|
||||
uint32_t cr; // control register (rw)
|
||||
uint32_t stat; // status register (r)
|
||||
uint32_t data; // data register (rw)
|
||||
uint32_t clk; // clock divisor register (rw)
|
||||
uint32_t ir;
|
||||
};
|
||||
typedef struct pl050_registers pl050_registers_t;
|
||||
|
||||
void pl050_keyboard_install();
|
||||
void pl050_mouse_install();
|
||||
|
||||
#endif //_KERNEL_DRIVERS_IO_ARM_PL050_H
|
||||
186
kernel/include/drivers/io/keyboard.h
Normal file
186
kernel/include/drivers/io/keyboard.h
Normal file
@@ -0,0 +1,186 @@
|
||||
#ifndef _KERNEL_DRIVERS_IO_KEYBOARD_H
|
||||
#define _KERNEL_DRIVERS_IO_KEYBOARD_H
|
||||
|
||||
#include <libkern/types.h>
|
||||
|
||||
enum KEYCODE {
|
||||
|
||||
// Alphanumeric keys ////////////////
|
||||
KEY_CTRLC = '\003',
|
||||
|
||||
KEY_SPACE = ' ',
|
||||
KEY_0 = '0',
|
||||
KEY_1 = '1',
|
||||
KEY_2 = '2',
|
||||
KEY_3 = '3',
|
||||
KEY_4 = '4',
|
||||
KEY_5 = '5',
|
||||
KEY_6 = '6',
|
||||
KEY_7 = '7',
|
||||
KEY_8 = '8',
|
||||
KEY_9 = '9',
|
||||
|
||||
KEY_A = 'a',
|
||||
KEY_B = 'b',
|
||||
KEY_C = 'c',
|
||||
KEY_D = 'd',
|
||||
KEY_E = 'e',
|
||||
KEY_F = 'f',
|
||||
KEY_G = 'g',
|
||||
KEY_H = 'h',
|
||||
KEY_I = 'i',
|
||||
KEY_J = 'j',
|
||||
KEY_K = 'k',
|
||||
KEY_L = 'l',
|
||||
KEY_M = 'm',
|
||||
KEY_N = 'n',
|
||||
KEY_O = 'o',
|
||||
KEY_P = 'p',
|
||||
KEY_Q = 'q',
|
||||
KEY_R = 'r',
|
||||
KEY_S = 's',
|
||||
KEY_T = 't',
|
||||
KEY_U = 'u',
|
||||
KEY_V = 'v',
|
||||
KEY_W = 'w',
|
||||
KEY_X = 'x',
|
||||
KEY_Y = 'y',
|
||||
KEY_Z = 'z',
|
||||
|
||||
KEY_RETURN = '\r',
|
||||
KEY_ESCAPE = 0x1001,
|
||||
KEY_BACKSPACE = '\b',
|
||||
|
||||
// Arrow keys ////////////////////////
|
||||
|
||||
KEY_UP = 0x1100,
|
||||
KEY_DOWN = 0x1101,
|
||||
KEY_LEFT = 0x1102,
|
||||
KEY_RIGHT = 0x1103,
|
||||
|
||||
// Function keys /////////////////////
|
||||
|
||||
KEY_F1 = 0x1201,
|
||||
KEY_F2 = 0x1202,
|
||||
KEY_F3 = 0x1203,
|
||||
KEY_F4 = 0x1204,
|
||||
KEY_F5 = 0x1205,
|
||||
KEY_F6 = 0x1206,
|
||||
KEY_F7 = 0x1207,
|
||||
KEY_F8 = 0x1208,
|
||||
KEY_F9 = 0x1209,
|
||||
KEY_F10 = 0x120a,
|
||||
KEY_F11 = 0x120b,
|
||||
KEY_F12 = 0x120b,
|
||||
KEY_F13 = 0x120c,
|
||||
KEY_F14 = 0x120d,
|
||||
KEY_F15 = 0x120e,
|
||||
|
||||
KEY_DOT = '.',
|
||||
KEY_COMMA = ',',
|
||||
KEY_COLON = ':',
|
||||
KEY_SEMICOLON = ';',
|
||||
KEY_SLASH = '/',
|
||||
KEY_BACKSLASH = '\\',
|
||||
KEY_PLUS = '+',
|
||||
KEY_MINUS = '-',
|
||||
KEY_ASTERISK = '*',
|
||||
KEY_EXCLAMATION = '!',
|
||||
KEY_QUESTION = '?',
|
||||
KEY_QUOTEDOUBLE = '\"',
|
||||
KEY_QUOTE = '\'',
|
||||
KEY_EQUAL = '=',
|
||||
KEY_HASH = '#',
|
||||
KEY_PERCENT = '%',
|
||||
KEY_AMPERSAND = '&',
|
||||
KEY_UNDERSCORE = '_',
|
||||
KEY_LEFTPARENTHESIS = '(',
|
||||
KEY_RIGHTPARENTHESIS = ')',
|
||||
KEY_LEFTBRACKET = '[',
|
||||
KEY_RIGHTBRACKET = ']',
|
||||
KEY_LEFTCURL = '{',
|
||||
KEY_RIGHTCURL = '}',
|
||||
KEY_DOLLAR = '$',
|
||||
KEY_POUND = 0,
|
||||
KEY_EURO = '$',
|
||||
KEY_LESS = '<',
|
||||
KEY_GREATER = '>',
|
||||
KEY_BAR = '|',
|
||||
KEY_GRAVE = '`',
|
||||
KEY_TILDE = '~',
|
||||
KEY_AT = '@',
|
||||
KEY_CARRET = '^',
|
||||
|
||||
// Numeric keypad //////////////////////
|
||||
|
||||
KEY_KP_0 = '0',
|
||||
KEY_KP_1 = '1',
|
||||
KEY_KP_2 = '2',
|
||||
KEY_KP_3 = '3',
|
||||
KEY_KP_4 = '4',
|
||||
KEY_KP_5 = '5',
|
||||
KEY_KP_6 = '6',
|
||||
KEY_KP_7 = '7',
|
||||
KEY_KP_8 = '8',
|
||||
KEY_KP_9 = '9',
|
||||
KEY_KP_PLUS = '+',
|
||||
KEY_KP_MINUS = '-',
|
||||
KEY_KP_DECIMAL = '.',
|
||||
KEY_KP_DIVIDE = '/',
|
||||
KEY_KP_ASTERISK = '*',
|
||||
KEY_KP_NUMLOCK = 0x300f,
|
||||
KEY_KP_ENTER = 0x3010,
|
||||
|
||||
KEY_TAB = 0x4000,
|
||||
KEY_CAPSLOCK = 0x4001,
|
||||
|
||||
// Modify keys ////////////////////////////
|
||||
|
||||
KEY_LSHIFT = 0x4002,
|
||||
KEY_LCTRL = 0x4003,
|
||||
KEY_LALT = 0x4004,
|
||||
KEY_LWIN = 0x4005,
|
||||
KEY_RSHIFT = 0x4006,
|
||||
KEY_RCTRL = 0x4007,
|
||||
KEY_RALT = 0x4008,
|
||||
KEY_RWIN = 0x4009,
|
||||
|
||||
KEY_INSERT = 0x400a,
|
||||
KEY_DELETE = 0x400b,
|
||||
KEY_HOME = 0x400c,
|
||||
KEY_END = 0x400d,
|
||||
KEY_PAGEUP = 0x400e,
|
||||
KEY_PAGEDOWN = 0x400f,
|
||||
KEY_SCROLLLOCK = 0x4010,
|
||||
KEY_PAUSE = 0x4011,
|
||||
|
||||
// Multimedia keys ////////////////////////
|
||||
|
||||
KEY_PREV_TRACK = 0x5001,
|
||||
KEY_NEXT_TRACK = 0x5002,
|
||||
KEY_MUTE = 0x5003,
|
||||
KEY_CALC = 0x5004,
|
||||
KEY_PLAY = 0x5005,
|
||||
KEY_STOP = 0x5006,
|
||||
KEY_VOL_DOWN = 0x5007,
|
||||
KEY_VOL_UP = 0x5008,
|
||||
|
||||
KEY_WWW_HOME = 0x500a,
|
||||
|
||||
KEY_UNKNOWN,
|
||||
KEY_NUMKEYCODES
|
||||
};
|
||||
|
||||
typedef uint32_t key_t;
|
||||
|
||||
/* The keyboard packet should be aligned to 4 bytes */
|
||||
struct kbd_packet {
|
||||
key_t key;
|
||||
};
|
||||
typedef struct kbd_packet kbd_packet_t;
|
||||
|
||||
int generic_keyboard_create_devfs();
|
||||
void generic_keyboard_init();
|
||||
void generic_emit_key_set1(uint32_t scancode);
|
||||
|
||||
#endif //_KERNEL_DRIVERS_IO_KEYBOARD_H
|
||||
180
kernel/include/drivers/io/keyboard_mappings/scancode_set1.h
Normal file
180
kernel/include/drivers/io/keyboard_mappings/scancode_set1.h
Normal file
@@ -0,0 +1,180 @@
|
||||
#include <drivers/io/keyboard.h>
|
||||
|
||||
static key_t _scancode_set1[] = {
|
||||
KEY_UNKNOWN, // 0
|
||||
KEY_ESCAPE, // 1
|
||||
KEY_1, // 2
|
||||
KEY_2, // 3
|
||||
KEY_3, // 4
|
||||
KEY_4, // 5
|
||||
KEY_5, // 6
|
||||
KEY_6, // 7
|
||||
KEY_7, // 8
|
||||
KEY_8, // 9
|
||||
KEY_9, // 0xa
|
||||
KEY_0, // 0xb
|
||||
KEY_MINUS, // 0xc
|
||||
KEY_EQUAL, // 0xd
|
||||
KEY_BACKSPACE, // 0xe
|
||||
KEY_TAB, // 0xf
|
||||
KEY_Q, // 0x10
|
||||
KEY_W, // 0x11
|
||||
KEY_E, // 0x12
|
||||
KEY_R, // 0x13
|
||||
KEY_T, // 0x14
|
||||
KEY_Y, // 0x15
|
||||
KEY_U, // 0x16
|
||||
KEY_I, // 0x17
|
||||
KEY_O, // 0x18
|
||||
KEY_P, // 0x19
|
||||
KEY_LEFTBRACKET, // 0x1a
|
||||
KEY_RIGHTBRACKET, // 0x1b
|
||||
KEY_RETURN, // 0x1c
|
||||
KEY_LCTRL, // 0x1d
|
||||
KEY_A, // 0x1e
|
||||
KEY_S, // 0x1f
|
||||
KEY_D, // 0x20
|
||||
KEY_F, // 0x21
|
||||
KEY_G, // 0x22
|
||||
KEY_H, // 0x23
|
||||
KEY_J, // 0x24
|
||||
KEY_K, // 0x25
|
||||
KEY_L, // 0x26
|
||||
KEY_SEMICOLON, // 0x27
|
||||
KEY_QUOTE, // 0x28
|
||||
KEY_GRAVE, // 0x29
|
||||
KEY_LSHIFT, // 0x2a
|
||||
KEY_BACKSLASH, // 0x2b
|
||||
KEY_Z, // 0x2c
|
||||
KEY_X, // 0x2d
|
||||
KEY_C, // 0x2e
|
||||
KEY_V, // 0x2f
|
||||
KEY_B, // 0x30
|
||||
KEY_N, // 0x31
|
||||
KEY_M, // 0x32
|
||||
KEY_COMMA, // 0x33
|
||||
KEY_DOT, // 0x34
|
||||
KEY_SLASH, // 0x35
|
||||
KEY_RSHIFT, // 0x36
|
||||
KEY_KP_ASTERISK, // 0x37
|
||||
KEY_RALT, // 0x38
|
||||
KEY_SPACE, // 0x39
|
||||
KEY_CAPSLOCK, // 0x3a
|
||||
KEY_F1, // 0x3b
|
||||
KEY_F2, // 0x3c
|
||||
KEY_F3, // 0x3d
|
||||
KEY_F4, // 0x3e
|
||||
KEY_F5, // 0x3f
|
||||
KEY_F6, // 0x40
|
||||
KEY_F7, // 0x41
|
||||
KEY_F8, // 0x42
|
||||
KEY_F9, // 0x43
|
||||
KEY_F10, // 0x44
|
||||
KEY_KP_NUMLOCK, // 0x45
|
||||
KEY_SCROLLLOCK, // 0x46
|
||||
KEY_HOME, // 0x47
|
||||
KEY_KP_8, // 0x48 //keypad up arrow
|
||||
KEY_PAGEUP, // 0x49
|
||||
KEY_KP_2, // 0x50 //keypad down arrow
|
||||
KEY_KP_3, // 0x51 //keypad page down
|
||||
KEY_KP_0, // 0x52 //keypad insert key
|
||||
KEY_KP_DECIMAL, // 0x53 //keypad delete key
|
||||
KEY_UNKNOWN, // 0x54
|
||||
KEY_UNKNOWN, // 0x55
|
||||
KEY_UNKNOWN, // 0x56
|
||||
KEY_F11, // 0x57
|
||||
KEY_F12 // 0x58
|
||||
};
|
||||
|
||||
static key_t _scancode_set1_upper[] = {
|
||||
KEY_UNKNOWN, // 0
|
||||
KEY_UNKNOWN, // 1
|
||||
KEY_UNKNOWN, // 2
|
||||
KEY_UNKNOWN, // 3
|
||||
KEY_UNKNOWN, // 4
|
||||
KEY_UNKNOWN, // 5
|
||||
KEY_UNKNOWN, // 6
|
||||
KEY_UNKNOWN, // 7
|
||||
KEY_UNKNOWN, // 8
|
||||
KEY_UNKNOWN, // 9
|
||||
KEY_UNKNOWN, // 0xa
|
||||
KEY_UNKNOWN, // 0xb
|
||||
KEY_UNKNOWN, // 0xc
|
||||
KEY_UNKNOWN, // 0xd
|
||||
KEY_UNKNOWN, // 0xe
|
||||
KEY_UNKNOWN, // 0xf
|
||||
KEY_PREV_TRACK, // 0x10
|
||||
KEY_UNKNOWN, // 0x11
|
||||
KEY_UNKNOWN, // 0x12
|
||||
KEY_UNKNOWN, // 0x13
|
||||
KEY_UNKNOWN, // 0x14
|
||||
KEY_UNKNOWN, // 0x15
|
||||
KEY_UNKNOWN, // 0x16
|
||||
KEY_UNKNOWN, // 0x17
|
||||
KEY_UNKNOWN, // 0x18
|
||||
KEY_NEXT_TRACK, // 0x19
|
||||
KEY_UNKNOWN, // 0x1a
|
||||
KEY_UNKNOWN, // 0x1b
|
||||
KEY_KP_ENTER, // 0x1c
|
||||
KEY_RCTRL, // 0x1d
|
||||
KEY_UNKNOWN, // 0x1e
|
||||
KEY_UNKNOWN, // 0x1f
|
||||
KEY_MUTE, // 0x20
|
||||
KEY_CALC, // 0x21
|
||||
KEY_PLAY, // 0x22
|
||||
KEY_UNKNOWN, // 0x23
|
||||
KEY_STOP, // 0x24
|
||||
KEY_UNKNOWN, // 0x25
|
||||
KEY_UNKNOWN, // 0x26
|
||||
KEY_UNKNOWN, // 0x27
|
||||
KEY_UNKNOWN, // 0x28
|
||||
KEY_UNKNOWN, // 0x29
|
||||
KEY_UNKNOWN, // 0x2a
|
||||
KEY_UNKNOWN, // 0x2b
|
||||
KEY_UNKNOWN, // 0x2c
|
||||
KEY_UNKNOWN, // 0x2d
|
||||
KEY_VOL_DOWN, // 0x2e
|
||||
KEY_UNKNOWN, // 0x2f
|
||||
KEY_VOL_UP, // 0x30
|
||||
KEY_UNKNOWN, // 0x31
|
||||
KEY_WWW_HOME, // 0x32
|
||||
KEY_UNKNOWN, // 0x33
|
||||
KEY_UNKNOWN, // 0x34
|
||||
KEY_NUMKEYCODES, // 0x35
|
||||
KEY_UNKNOWN, // 0x36
|
||||
KEY_UNKNOWN, // 0x37
|
||||
KEY_RALT, // 0x38
|
||||
KEY_UNKNOWN, // 0x39
|
||||
KEY_UNKNOWN, // 0x3a
|
||||
KEY_UNKNOWN, // 0x3b
|
||||
KEY_UNKNOWN, // 0x3c
|
||||
KEY_UNKNOWN, // 0x3d
|
||||
KEY_UNKNOWN, // 0x3e
|
||||
KEY_UNKNOWN, // 0x3f
|
||||
KEY_UNKNOWN, // 0x40
|
||||
KEY_UNKNOWN, // 0x41
|
||||
KEY_UNKNOWN, // 0x42
|
||||
KEY_UNKNOWN, // 0x43
|
||||
KEY_UNKNOWN, // 0x44
|
||||
KEY_UNKNOWN, // 0x45
|
||||
KEY_UNKNOWN, // 0x46
|
||||
KEY_HOME, // 0x47
|
||||
KEY_UP, // 0x48
|
||||
KEY_PAGEUP, // 0x49
|
||||
KEY_UNKNOWN, // 0x4a
|
||||
KEY_LEFT, // 0x4b
|
||||
KEY_UNKNOWN, // 0x4c
|
||||
KEY_RIGHT, // 0x4d
|
||||
KEY_UNKNOWN, // 0x4e
|
||||
KEY_END, // 0x4f
|
||||
KEY_DOWN, // 0x50
|
||||
KEY_PAGEDOWN, // 0x51
|
||||
KEY_INSERT, // 0x52
|
||||
KEY_DELETE // 0x53
|
||||
};
|
||||
|
||||
static inline key_t generic_keyboard_get_keycode_set1(uint32_t scancode)
|
||||
{
|
||||
key_t* lookup_table[] = { _scancode_set1, _scancode_set1_upper };
|
||||
return lookup_table[(scancode >> 8) & 1][scancode & ~((uint32_t)0x100)];
|
||||
}
|
||||
19
kernel/include/drivers/io/mouse.h
Normal file
19
kernel/include/drivers/io/mouse.h
Normal file
@@ -0,0 +1,19 @@
|
||||
#ifndef _KERNEL_DRIVERS_IO_MOUSE_H
|
||||
#define _KERNEL_DRIVERS_IO_MOUSE_H
|
||||
|
||||
#include <libkern/types.h>
|
||||
|
||||
/* The mouse packet should be aligned to 4 bytes */
|
||||
struct mouse_packet {
|
||||
int16_t x_offset;
|
||||
int16_t y_offset;
|
||||
uint16_t button_states;
|
||||
int16_t wheel_data;
|
||||
};
|
||||
typedef struct mouse_packet mouse_packet_t;
|
||||
|
||||
int generic_mouse_create_devfs();
|
||||
void generic_mouse_init();
|
||||
void generic_mouse_send_packet(mouse_packet_t* packet);
|
||||
|
||||
#endif //_KERNEL_DRIVERS_IO_MOUSE_H
|
||||
28
kernel/include/drivers/io/virtio_input.h
Normal file
28
kernel/include/drivers/io/virtio_input.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef _KERNEL_DRIVERS_STORAGE_VIRTIO_INPUT_H
|
||||
#define _KERNEL_DRIVERS_STORAGE_VIRTIO_INPUT_H
|
||||
|
||||
#include <drivers/driver_manager.h>
|
||||
#include <drivers/irq/irq_api.h>
|
||||
#include <drivers/virtio/virtio.h>
|
||||
#include <libkern/types.h>
|
||||
#include <mem/kmalloc.h>
|
||||
|
||||
struct virtio_input_event {
|
||||
int16_t event_type;
|
||||
int16_t code;
|
||||
int32_t value;
|
||||
};
|
||||
typedef struct virtio_input_event virtio_input_event_t;
|
||||
|
||||
struct virtio_input_dev {
|
||||
virtio_queue_desc_t event_queue_desc;
|
||||
virtio_queue_desc_t status_queue_desc;
|
||||
uint32_t status_ack_used_idx;
|
||||
uint32_t event_idx;
|
||||
uint32_t event_ack_used_idx;
|
||||
virtio_buffer_desc_t event_buffer_desc;
|
||||
irq_line_t irq_line;
|
||||
};
|
||||
typedef struct virtio_input_dev virtio_input_dev_t;
|
||||
|
||||
#endif //_KERNEL_DRIVERS_STORAGE_VIRTIO_INPUT_H
|
||||
13
kernel/include/drivers/io/x86/keyboard.h
Normal file
13
kernel/include/drivers/io/x86/keyboard.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef _KERNEL_DRIVERS_IO_X86_KEYBOARD_H
|
||||
#define _KERNEL_DRIVERS_IO_X86_KEYBOARD_H
|
||||
|
||||
#include <drivers/io/keyboard.h>
|
||||
#include <libkern/types.h>
|
||||
|
||||
void kbdriver_install();
|
||||
int kbdriver_run();
|
||||
|
||||
uint32_t kbdriver_get_last_key();
|
||||
void kbdriver_discard_last_key();
|
||||
|
||||
#endif
|
||||
9
kernel/include/drivers/io/x86/mouse.h
Normal file
9
kernel/include/drivers/io/x86/mouse.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef _KERNEL_DRIVERS_IO_X86_MOUSE_H
|
||||
#define _KERNEL_DRIVERS_IO_X86_MOUSE_H
|
||||
|
||||
#include <drivers/io/mouse.h>
|
||||
#include <libkern/types.h>
|
||||
|
||||
void mouse_install();
|
||||
|
||||
#endif // _KERNEL_DRIVERS_IO_X86_MOUSE_H
|
||||
69
kernel/include/drivers/irq/arm/gicv2.h
Normal file
69
kernel/include/drivers/irq/arm/gicv2.h
Normal file
@@ -0,0 +1,69 @@
|
||||
#ifndef _KERNEL_DRIVERS_IRQ_ARM_GICV2_H
|
||||
#define _KERNEL_DRIVERS_IRQ_ARM_GICV2_H
|
||||
|
||||
#include <drivers/driver_manager.h>
|
||||
#include <drivers/irq/irq_api.h>
|
||||
#include <libkern/mask.h>
|
||||
#include <libkern/types.h>
|
||||
|
||||
enum GICDControlMasks {
|
||||
MASKDEFINE(GICD_ENABLE, 0, 1),
|
||||
};
|
||||
|
||||
enum GICCControlMasks {
|
||||
MASKDEFINE(GICC_ENABLE_GR1, 0, 1),
|
||||
MASKDEFINE(GICC_FIQ_BYP_DIS_GR1, 5, 1),
|
||||
MASKDEFINE(GICC_IRQ_BYP_DIS_GR1, 6, 1),
|
||||
MASKDEFINE(GICC_EO_IMODE_NS, 9, 1),
|
||||
};
|
||||
|
||||
struct gicv2_distributor_registers {
|
||||
uint32_t control;
|
||||
uint32_t typer;
|
||||
uint32_t iidr;
|
||||
SKIP(0x008 + 0x4, 0x080);
|
||||
uint32_t igroup[8];
|
||||
SKIP(0x09C + 0x4, 0x100);
|
||||
uint32_t isenabler[8];
|
||||
SKIP(0x11C + 0x4, 0x180);
|
||||
uint32_t icenabler[8];
|
||||
SKIP(0x19C + 0x4, 0x200);
|
||||
uint32_t ispendr[8];
|
||||
SKIP(0x21C + 0x4, 0x280);
|
||||
uint32_t icpendr[8];
|
||||
SKIP(0x29C + 0x4, 0x300);
|
||||
uint32_t isactiver[8];
|
||||
SKIP(0x31C + 0x4, 0x380);
|
||||
uint32_t icactiver[8];
|
||||
SKIP(0x39C + 0x4, 0x400);
|
||||
uint32_t ipriorityr[64];
|
||||
SKIP(0x4FC + 0x4, 0x800);
|
||||
uint32_t itargetsr[64];
|
||||
SKIP(0x8FC + 0x4, 0xC00);
|
||||
uint32_t icfgr[16];
|
||||
// TO BE CONTINUED
|
||||
};
|
||||
typedef struct gicv2_distributor_registers gicv2_distributor_registers_t;
|
||||
|
||||
struct gicv2_cpu_interface_registers {
|
||||
uint32_t control;
|
||||
uint32_t pmr;
|
||||
uint32_t bpr;
|
||||
uint32_t iar;
|
||||
uint32_t eoir;
|
||||
uint32_t hppir;
|
||||
uint32_t abpr;
|
||||
uint32_t aiar;
|
||||
uint32_t aeoir;
|
||||
uint32_t ahppir;
|
||||
// TO BE CONTINUED
|
||||
};
|
||||
typedef struct gicv2_cpu_interface_registers gicv2_cpu_interface_registers_t;
|
||||
|
||||
void gicv2_enable_irq(irq_line_t id, irq_priority_t prior, irq_flags_t flags, int cpu_mask);
|
||||
void gicv2_install();
|
||||
void gicv2_install_secondary_cpu();
|
||||
uint32_t gicv2_interrupt_descriptor();
|
||||
void gicv2_end(uint32_t int_disc);
|
||||
|
||||
#endif //_KERNEL_DRIVERS_IRQ_ARM_GICV2_H
|
||||
35
kernel/include/drivers/irq/irq_api.h
Normal file
35
kernel/include/drivers/irq/irq_api.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef _KERNEL_DRIVERS_IRQ_IRQ_API_H
|
||||
#define _KERNEL_DRIVERS_IRQ_IRQ_API_H
|
||||
|
||||
#include <libkern/types.h>
|
||||
|
||||
// This value shows the maximum number of irqs OS supports. It is irqdev independent,
|
||||
// thus irqdev implementations should double check the irqlines.
|
||||
#define IRQ_HANDLERS_MAX 256
|
||||
|
||||
#define ALL_CPU_MASK 0xff
|
||||
#define BOOT_CPU_MASK 0x01
|
||||
|
||||
typedef int irq_flags_t;
|
||||
typedef int irq_line_t;
|
||||
typedef uint8_t irq_priority_t;
|
||||
typedef void (*irq_handler_t)(irq_line_t line);
|
||||
|
||||
// Currently flags maps to devtree irq_flags.
|
||||
// Later we might need to enhance irq_flags_from_devtree() to use as translator.
|
||||
#define IRQ_FLAG_EDGE_TRIGGERED (1 << 0)
|
||||
|
||||
struct irqdev_descritptor {
|
||||
uint32_t (*interrupt_descriptor)();
|
||||
void (*end_interrupt)(uint32_t int_desc);
|
||||
void (*enable_irq)(irq_line_t line, irq_priority_t prior, irq_flags_t type, int cpu_mask);
|
||||
};
|
||||
typedef struct irqdev_descritptor irqdev_descritptor_t;
|
||||
|
||||
static inline irq_flags_t irq_flags_from_devtree(uint32_t devtree_irq_flags) { return (irq_flags_t)devtree_irq_flags; }
|
||||
|
||||
void irq_register_handler(irq_line_t line, irq_priority_t prior, irq_flags_t flags, irq_handler_t func, int cpu_mask);
|
||||
void irq_set_dev(irqdev_descritptor_t irqdev_desc);
|
||||
irq_line_t irqline_from_id(int id);
|
||||
|
||||
#endif
|
||||
12
kernel/include/drivers/irq/riscv/plic.h
Normal file
12
kernel/include/drivers/irq/riscv/plic.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef _KERNEL_DRIVERS_IRQ_RISCV_PLIC_H
|
||||
#define _KERNEL_DRIVERS_IRQ_RISCV_PLIC_H
|
||||
|
||||
#include <drivers/driver_manager.h>
|
||||
#include <drivers/irq/irq_api.h>
|
||||
|
||||
void plic_install();
|
||||
void plic_enable_irq(irq_line_t id, irq_priority_t prior, irq_flags_t flags, int cpu_mask);
|
||||
uint32_t plic_interrupt_descriptor();
|
||||
void plic_end(uint32_t id);
|
||||
|
||||
#endif //_KERNEL_DRIVERS_IRQ_RISCV_PLIC_H
|
||||
14
kernel/include/drivers/irq/x86/pic.h
Normal file
14
kernel/include/drivers/irq/x86/pic.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef _KERNEL_DRIVERS_IRQ_X86_PIC_H
|
||||
#define _KERNEL_DRIVERS_IRQ_X86_PIC_H
|
||||
|
||||
#include <platform/x86/port.h>
|
||||
|
||||
#define MASTER_PIC_CMD 0x0020
|
||||
#define MASTER_PIC_DATA 0x0021
|
||||
#define SLAVE_PIC_CMD 0x00A0
|
||||
#define SLAVE_PIC_DATA 0x00A1
|
||||
#define ICW4_8086 0x01
|
||||
|
||||
void pic_remap(unsigned int offset1, unsigned int offset2);
|
||||
|
||||
#endif
|
||||
9
kernel/include/drivers/serial/arm/uart.h
Normal file
9
kernel/include/drivers/serial/arm/uart.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef _KERNEL_DRIVERS_SERIAL_ARM_UART_H
|
||||
#define _KERNEL_DRIVERS_SERIAL_ARM_UART_H
|
||||
|
||||
#include <drivers/serial/uart_api.h>
|
||||
#include <libkern/types.h>
|
||||
|
||||
void uart_remap();
|
||||
|
||||
#endif /* _KERNEL_DRIVERS_SERIAL_ARM_UART_H */
|
||||
9
kernel/include/drivers/serial/riscv/uart.h
Normal file
9
kernel/include/drivers/serial/riscv/uart.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef _KERNEL_DRIVERS_SERIAL_RISCV_UART_H
|
||||
#define _KERNEL_DRIVERS_SERIAL_RISCV_UART_H
|
||||
|
||||
#include <drivers/serial/uart_api.h>
|
||||
#include <libkern/types.h>
|
||||
|
||||
void uart_remap();
|
||||
|
||||
#endif /* _KERNEL_DRIVERS_SERIAL_RISCV_UART_H */
|
||||
11
kernel/include/drivers/serial/uart_api.h
Normal file
11
kernel/include/drivers/serial/uart_api.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef _KERNEL_DRIVERS_SERIAL_UART_API_H
|
||||
#define _KERNEL_DRIVERS_SERIAL_UART_API_H
|
||||
|
||||
#include <libkern/types.h>
|
||||
|
||||
struct boot_args;
|
||||
void uart_setup(struct boot_args* boot_args);
|
||||
int uart_write(uint8_t data);
|
||||
int uart_read(uint8_t* data);
|
||||
|
||||
#endif //_KERNEL_DRIVERS_SERIAL_UART_API_H
|
||||
12
kernel/include/drivers/serial/x86/uart.h
Normal file
12
kernel/include/drivers/serial/x86/uart.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef _KERNEL_DRIVERS_SERIAL_X86_UART_H
|
||||
#define _KERNEL_DRIVERS_SERIAL_X86_UART_H
|
||||
|
||||
#include <drivers/serial/uart_api.h>
|
||||
#include <libkern/types.h>
|
||||
|
||||
#define COM1 0x3F8
|
||||
#define COM2 0x2F8
|
||||
#define COM3 0x3E8
|
||||
#define COM4 0x2E8
|
||||
|
||||
#endif //_KERNEL_DRIVERS_SERIAL_X86_UART_H
|
||||
74
kernel/include/drivers/storage/arm/pl181.h
Normal file
74
kernel/include/drivers/storage/arm/pl181.h
Normal file
@@ -0,0 +1,74 @@
|
||||
#ifndef _KERNEL_DRIVERS_STORAGE_ARM_PL181_H
|
||||
#define _KERNEL_DRIVERS_STORAGE_ARM_PL181_H
|
||||
|
||||
#include <drivers/driver_manager.h>
|
||||
#include <libkern/mask.h>
|
||||
#include <libkern/types.h>
|
||||
|
||||
#define PL181_SECTOR_SIZE 512
|
||||
|
||||
enum PL181CommandMasks {
|
||||
MASKDEFINE(MMC_CMD_IDX, 0, 6),
|
||||
MASKDEFINE(MMC_CMD_RESP, 6, 1),
|
||||
MASKDEFINE(MMC_CMD_LONG_RESP, 7, 1),
|
||||
MASKDEFINE(MMC_CMD_INTERRUPT, 8, 1),
|
||||
MASKDEFINE(MMC_CMD_PENDING, 9, 1),
|
||||
MASKDEFINE(MMC_CMD_ENABLE, 10, 1),
|
||||
};
|
||||
|
||||
enum PL181StatusMasks {
|
||||
MASKDEFINE(MMC_STAT_CRC_FAIL, 0, 1),
|
||||
MASKDEFINE(MMC_STAT_CMD_TIMEOUT, 2, 1),
|
||||
MASKDEFINE(MMC_STAT_CMD_RESP_END, 6, 1),
|
||||
MASKDEFINE(MMC_STAT_CMD_SENT, 7, 1),
|
||||
MASKDEFINE(MMC_STAT_CMD_ACTIVE, 11, 1),
|
||||
MASKDEFINE(MMC_STAT_TRANSMIT_FIFO_EMPTY, 18, 1),
|
||||
MASKDEFINE(MMC_STAT_FIFO_DATA_AVAIL_TO_READ, 21, 1),
|
||||
};
|
||||
|
||||
enum PL181Commands {
|
||||
CMD_GO_IDLE_STATE = 0,
|
||||
CMD_ALL_SEND_CID = 2,
|
||||
CMD_SET_RELATIVE_ADDR = 3,
|
||||
CMD_SELECT = 7,
|
||||
CMD_SEND_CSD = 9,
|
||||
CMD_SEND_CID = 10,
|
||||
CMD_SET_SECTOR_SIZE = 16,
|
||||
CMD_READ_SINGLE_BLOCK = 17,
|
||||
CMD_WRITE_SINGLE_BLOCK = 24,
|
||||
CMD_SD_SEND_OP_COND = 41,
|
||||
CMD_APP_CMD = 55,
|
||||
};
|
||||
|
||||
struct pl181_registers {
|
||||
uint32_t power;
|
||||
uint32_t clock;
|
||||
uint32_t arg;
|
||||
uint32_t cmd;
|
||||
uint32_t resp_cmd;
|
||||
uint32_t response[4];
|
||||
uint32_t data_timer;
|
||||
uint32_t data_length;
|
||||
uint32_t data_control;
|
||||
uint32_t data_count;
|
||||
uint32_t status;
|
||||
uint32_t clear;
|
||||
uint32_t interrupt_mask[2];
|
||||
uint32_t interrupt_select;
|
||||
uint32_t fifo_count;
|
||||
char res[0x34];
|
||||
uint32_t fifo_data[16];
|
||||
// TO BE CONTINUED
|
||||
};
|
||||
typedef struct pl181_registers pl181_registers_t;
|
||||
|
||||
struct sd_card {
|
||||
uint32_t rca;
|
||||
uint32_t ishc;
|
||||
uint32_t capacity;
|
||||
};
|
||||
typedef struct sd_card sd_card_t;
|
||||
|
||||
void pl181_install();
|
||||
|
||||
#endif //_KERNEL_DRIVERS_STORAGE_ARM_PL181_H
|
||||
9
kernel/include/drivers/storage/ramdisk.h
Normal file
9
kernel/include/drivers/storage/ramdisk.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef _KERNEL_DRIVERS_STORAGE_RAMDISK_H
|
||||
#define _KERNEL_DRIVERS_STORAGE_RAMDISK_H
|
||||
|
||||
#include <drivers/driver_manager.h>
|
||||
#include <libkern/types.h>
|
||||
|
||||
void ramdisk_install();
|
||||
|
||||
#endif //_KERNEL_DRIVERS_STORAGE_RAMDISK_H
|
||||
58
kernel/include/drivers/storage/virtio_block.h
Normal file
58
kernel/include/drivers/storage/virtio_block.h
Normal file
@@ -0,0 +1,58 @@
|
||||
#ifndef _KERNEL_DRIVERS_STORAGE_VIRTIO_BLOCK_H
|
||||
#define _KERNEL_DRIVERS_STORAGE_VIRTIO_BLOCK_H
|
||||
|
||||
#include <drivers/driver_manager.h>
|
||||
#include <drivers/virtio/virtio.h>
|
||||
#include <libkern/types.h>
|
||||
#include <mem/kmalloc.h>
|
||||
|
||||
#define VIRTIO_BLK_T_IN (0)
|
||||
#define VIRTIO_BLK_T_OUT (1)
|
||||
#define VIRTIO_BLK_T_FLUSH (4)
|
||||
#define VIRTIO_BLK_T_DISCARD (11)
|
||||
#define VIRTIO_BLK_T_WRITE_ZEROES (13)
|
||||
|
||||
// Status values
|
||||
#define VIRTIO_BLK_S_OK (0)
|
||||
#define VIRTIO_BLK_S_IOERR (1)
|
||||
#define VIRTIO_BLK_S_UNSUPP (2)
|
||||
|
||||
// Feature bits
|
||||
#define VIRTIO_BLK_F_SIZE_MAX (1)
|
||||
#define VIRTIO_BLK_F_SEG_MAX (2)
|
||||
#define VIRTIO_BLK_F_GEOMETRY (4)
|
||||
#define VIRTIO_BLK_F_RO (5)
|
||||
#define VIRTIO_BLK_F_BLK_SIZE (6)
|
||||
#define VIRTIO_BLK_F_FLUSH (9)
|
||||
#define VIRTIO_BLK_F_TOPOLOGY (10)
|
||||
#define VIRTIO_BLK_F_CONFIG_WCE (11)
|
||||
#define VIRTIO_BLK_F_DISCARD (13)
|
||||
#define VIRTIO_BLK_F_WRITE_ZEROES (14)
|
||||
|
||||
struct block_dev {
|
||||
virtio_queue_desc_t queue_desc;
|
||||
void* ptr;
|
||||
uint32_t idx;
|
||||
uint32_t ack_used_idx;
|
||||
virtio_buffer_desc_t buffer_desc;
|
||||
};
|
||||
typedef struct block_dev block_dev_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t blktype;
|
||||
uint32_t reserved;
|
||||
uint64_t sector;
|
||||
} block_header_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t status;
|
||||
} block_status_t;
|
||||
|
||||
typedef struct {
|
||||
block_header_t header;
|
||||
block_status_t status;
|
||||
uint16_t head;
|
||||
uint16_t watcher;
|
||||
} block_request_t;
|
||||
|
||||
#endif //_KERNEL_DRIVERS_STORAGE_VIRTIO_BLOCK_H
|
||||
40
kernel/include/drivers/storage/x86/ata.h
Normal file
40
kernel/include/drivers/storage/x86/ata.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#ifndef _KERNEL_DRIVERS_STORAGE_X86_ATA_H
|
||||
#define _KERNEL_DRIVERS_STORAGE_X86_ATA_H
|
||||
|
||||
#include <drivers/driver_manager.h>
|
||||
#include <libkern/types.h>
|
||||
#include <mem/kmalloc.h>
|
||||
#include <platform/x86/port.h>
|
||||
|
||||
typedef struct { // LBA28 | LBA48
|
||||
uint32_t data; // 16bit | 16 bits
|
||||
uint32_t error; // 8 bit | 16 bits
|
||||
uint32_t sector_count; // 8 bit | 16 bits
|
||||
uint32_t lba_lo; // 8 bit | 16 bits
|
||||
uint32_t lba_mid; // 8 bit | 16 bits
|
||||
uint32_t lba_hi; // 8 bit | 16 bits
|
||||
uint32_t device; // 8 bit
|
||||
uint32_t command; // 8 bit
|
||||
uint32_t control;
|
||||
} ata_ports_t;
|
||||
|
||||
typedef struct {
|
||||
ata_ports_t port;
|
||||
bool is_master;
|
||||
uint16_t cylindres;
|
||||
uint16_t heads;
|
||||
uint16_t sectors;
|
||||
bool dma;
|
||||
bool lba;
|
||||
uint32_t capacity; // in sectors
|
||||
} ata_t;
|
||||
|
||||
extern ata_t _ata_drives[MAX_DEVICES_COUNT];
|
||||
|
||||
int ata_init_with_dev(device_t* dev);
|
||||
|
||||
void ata_install();
|
||||
void ata_init(ata_t* ata, uint32_t port, bool is_master);
|
||||
bool ata_indentify(ata_t* ata);
|
||||
|
||||
#endif //_KERNEL_DRIVERS_STORAGE_X86_ATA_H
|
||||
10
kernel/include/drivers/timer/arm/arm64/timer.h
Normal file
10
kernel/include/drivers/timer/arm/arm64/timer.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef _KERNEL_DRIVERS_TIMER_ARM_ARM64_TIMER_H
|
||||
#define _KERNEL_DRIVERS_TIMER_ARM_ARM64_TIMER_H
|
||||
|
||||
#include <libkern/types.h>
|
||||
#include <time/time_manager.h>
|
||||
|
||||
void arm64_timer_rearm();
|
||||
void arm64_timer_install();
|
||||
|
||||
#endif // _KERNEL_DRIVERS_TIMER_ARM_ARM64_TIMER_H
|
||||
34
kernel/include/drivers/timer/arm/sp804.h
Normal file
34
kernel/include/drivers/timer/arm/sp804.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef _KERNEL_DRIVERS_TIMER_ARM_SP804_H
|
||||
#define _KERNEL_DRIVERS_TIMER_ARM_SP804_H
|
||||
|
||||
#include <drivers/driver_manager.h>
|
||||
#include <libkern/mask.h>
|
||||
#include <libkern/types.h>
|
||||
#include <time/time_manager.h>
|
||||
|
||||
#define SP804_CLK_HZ 1000000
|
||||
|
||||
// https://developer.arm.com/documentation/ddi0271/d/programmer-s-model/register-descriptions/control-register--timerxcontrol?lang=en
|
||||
enum SP804ControlMasks {
|
||||
MASKDEFINE(SP804_ONE_SHOT, 0, 1),
|
||||
MASKDEFINE(SP804_32_BIT, 1, 1),
|
||||
MASKDEFINE(SP804_PRESCALE, 2, 2),
|
||||
MASKDEFINE(SP804_INTS_ENABLED, 5, 1),
|
||||
MASKDEFINE(SP804_PERIODIC, 6, 1),
|
||||
MASKDEFINE(SP804_ENABLE, 7, 1),
|
||||
};
|
||||
|
||||
struct sp804_registers {
|
||||
uint32_t load;
|
||||
uint32_t value;
|
||||
uint32_t control;
|
||||
uint32_t intclr;
|
||||
uint32_t ris;
|
||||
uint32_t mis;
|
||||
uint32_t bg_load;
|
||||
};
|
||||
typedef struct sp804_registers sp804_registers_t;
|
||||
|
||||
void sp804_install();
|
||||
|
||||
#endif //_KERNEL_DRIVERS_TIMER_ARM_SP804_H
|
||||
11
kernel/include/drivers/timer/x86/pit.h
Normal file
11
kernel/include/drivers/timer/x86/pit.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#ifndef _KERNEL_DRIVERS_TIMER_X86_PIT_H
|
||||
#define _KERNEL_DRIVERS_TIMER_X86_PIT_H
|
||||
|
||||
#include <libkern/types.h>
|
||||
#include <time/time_manager.h>
|
||||
|
||||
#define PIT_BASE_FREQ 1193180
|
||||
|
||||
void pit_setup();
|
||||
|
||||
#endif /* _KERNEL_DRIVERS_TIMER_X86_PIT_H */
|
||||
186
kernel/include/drivers/virtio/virtio.h
Normal file
186
kernel/include/drivers/virtio/virtio.h
Normal file
@@ -0,0 +1,186 @@
|
||||
#ifndef _KERNEL_DRIVERS_VIRTIO_VIRTIO_H
|
||||
#define _KERNEL_DRIVERS_VIRTIO_VIRTIO_H
|
||||
|
||||
#include <drivers/driver_manager.h>
|
||||
#include <libkern/mask.h>
|
||||
#include <libkern/types.h>
|
||||
#include <platform/generic/vmm/consts.h>
|
||||
#include <time/time_manager.h>
|
||||
|
||||
#define VIRTIO_DESC_F_NEXT (1)
|
||||
#define VIRTIO_DESC_F_WRITE (2)
|
||||
#define VIRTIO_DESC_F_INDIRECT (4)
|
||||
|
||||
#define VIRTIO_F_EVENT_IDX (1 << 29)
|
||||
|
||||
#define VIRTIO_RING_SIZE (1 << 7)
|
||||
|
||||
enum VIRTIO_DEVTYPE {
|
||||
VIRTIO_DEVTYPE_NETWORK = 1,
|
||||
VIRTIO_DEVTYPE_BLOCK = 2,
|
||||
VIRTIO_DEVTYPE_GPU = 16,
|
||||
VIRTIO_DEVTYPE_IO = 18,
|
||||
};
|
||||
|
||||
enum VIRTIO_STATUS {
|
||||
VIRTIO_STATUS_ACK = 1,
|
||||
VIRTIO_STATUS_DRIVER = 2,
|
||||
VIRTIO_STATUS_DRIVER_OK = 4,
|
||||
VIRTIO_STATUS_FEATS_OK = 8,
|
||||
VIRTIO_STATUS_DEV_NEEDS_RESET = 64,
|
||||
VIRTIO_STATUS_FAILED = 128,
|
||||
};
|
||||
|
||||
struct virtio_mmio_registers {
|
||||
uint32_t magic_value;
|
||||
uint32_t version;
|
||||
uint32_t device_id;
|
||||
uint32_t vendor_id;
|
||||
uint32_t host_features;
|
||||
uint32_t host_features_sel;
|
||||
uint8_t reserved1[8];
|
||||
uint32_t guest_features;
|
||||
uint32_t guest_features_sel;
|
||||
uint32_t guest_page_size;
|
||||
uint8_t reserved2[4];
|
||||
uint32_t queue_sel;
|
||||
uint32_t queue_num_max;
|
||||
uint32_t queue_num;
|
||||
uint32_t queue_align;
|
||||
uint64_t queue_pfn;
|
||||
uint8_t reserved3[8];
|
||||
uint32_t queue_notify;
|
||||
uint8_t reserved4[12];
|
||||
uint32_t interrupt_status;
|
||||
uint32_t interrupt_ack;
|
||||
uint8_t reserved5[8];
|
||||
uint32_t status;
|
||||
uint8_t reserved6[140];
|
||||
uint32_t config[1];
|
||||
};
|
||||
typedef struct virtio_mmio_registers virtio_mmio_registers_t;
|
||||
|
||||
struct virtio_desc {
|
||||
uint64_t addr;
|
||||
uint32_t len;
|
||||
uint16_t flags;
|
||||
uint16_t next;
|
||||
};
|
||||
typedef struct virtio_desc virtio_desc_t;
|
||||
|
||||
struct virtio_avail {
|
||||
uint16_t flags;
|
||||
uint16_t idx;
|
||||
uint16_t ring[VIRTIO_RING_SIZE];
|
||||
uint16_t event;
|
||||
};
|
||||
typedef struct virtio_avail virtio_avail_t;
|
||||
|
||||
struct virtio_used_elem {
|
||||
uint32_t id;
|
||||
uint32_t len;
|
||||
};
|
||||
typedef struct virtio_used_elem virtio_used_elem_t;
|
||||
|
||||
struct virtio_used {
|
||||
uint16_t flags;
|
||||
uint16_t idx;
|
||||
virtio_used_elem_t ring[VIRTIO_RING_SIZE];
|
||||
uint16_t event;
|
||||
};
|
||||
typedef struct virtio_used virtio_used_t;
|
||||
|
||||
struct virtio_desc_array {
|
||||
virtio_desc_t entities[VIRTIO_RING_SIZE];
|
||||
};
|
||||
typedef struct virtio_desc_array virtio_desc_array_t;
|
||||
|
||||
struct virtio_queue {
|
||||
virtio_desc_t desc[VIRTIO_RING_SIZE];
|
||||
virtio_avail_t avail;
|
||||
uint8_t padding0[4096 - sizeof(virtio_desc_t) * VIRTIO_RING_SIZE - sizeof(virtio_avail_t)];
|
||||
virtio_used_t used;
|
||||
};
|
||||
typedef struct virtio_queue virtio_queue_t;
|
||||
|
||||
struct virtio_alloc_result {
|
||||
void* req_vaddr;
|
||||
void* req_paddr;
|
||||
void* mem_vaddr;
|
||||
void* mem_paddr;
|
||||
void* resp_vaddr;
|
||||
void* resp_paddr;
|
||||
};
|
||||
typedef struct virtio_alloc_result virtio_alloc_result_t;
|
||||
|
||||
struct virtio_buffer_desc {
|
||||
union {
|
||||
uintptr_t vaddr;
|
||||
void* ptr;
|
||||
};
|
||||
uintptr_t paddr;
|
||||
kmemzone_t kzone;
|
||||
};
|
||||
typedef struct virtio_buffer_desc virtio_buffer_desc_t;
|
||||
|
||||
struct virtio_queue_desc {
|
||||
// These are vaddrs.
|
||||
virtio_desc_array_t* descs;
|
||||
virtio_avail_t* avail;
|
||||
virtio_used_t* used;
|
||||
|
||||
// Start of the queue.
|
||||
uintptr_t paddr;
|
||||
};
|
||||
typedef struct virtio_queue_desc virtio_queue_desc_t;
|
||||
|
||||
int virtio_alloc_buffer(size_t size, virtio_buffer_desc_t* result);
|
||||
int virtio_alloc_queue(virtio_queue_desc_t* result);
|
||||
|
||||
int virtio_alloc_init();
|
||||
int virtio_alloc(size_t size, virtio_alloc_result_t* result);
|
||||
void virtio_free_paddr(void* paddr_ptr);
|
||||
|
||||
#define virtio_alloc_raw(req_ptr, result) do_virtio_alloc_raw(req_ptr, sizeof(*req_ptr), result)
|
||||
static int do_virtio_alloc_raw(void* req_ptr, size_t req_size, virtio_alloc_result_t* result)
|
||||
{
|
||||
int err = virtio_alloc(req_size, result);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
memcpy(result->req_vaddr, req_ptr, req_size);
|
||||
return err;
|
||||
}
|
||||
|
||||
#define virtio_alloc_request(req_ptr, resp_ptr, result) do_virtio_alloc_request(req_ptr, sizeof(*req_ptr), resp_ptr, sizeof(*resp_ptr), result)
|
||||
static int do_virtio_alloc_request(void* req_ptr, size_t req_size, void* resp_ptr, size_t resp_size, virtio_alloc_result_t* result)
|
||||
{
|
||||
int err = virtio_alloc(req_size + resp_size, result);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
result->resp_vaddr = (void*)((uintptr_t)result->req_vaddr + req_size);
|
||||
result->resp_paddr = (void*)((uintptr_t)result->req_paddr + req_size);
|
||||
memcpy(result->req_vaddr, req_ptr, req_size);
|
||||
memcpy(result->resp_vaddr, resp_ptr, resp_size);
|
||||
return err;
|
||||
}
|
||||
|
||||
#define virtio_alloc_mem_request(req_ptr, mem_ptr, resp_ptr, result) do_alloc_mem_request(req_ptr, sizeof(*req_ptr), mem_ptr, sizeof(*mem_ptr), resp_ptr, sizeof(*resp_ptr), result)
|
||||
static int do_alloc_mem_request(void* req_ptr, size_t req_size, void* mem_ptr, size_t mem_size, void* resp_ptr, size_t resp_size, virtio_alloc_result_t* result)
|
||||
{
|
||||
int err = virtio_alloc(req_size + mem_size + resp_size, result);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
result->mem_vaddr = (void*)((uintptr_t)result->req_vaddr + req_size);
|
||||
result->mem_paddr = (void*)((uintptr_t)result->req_paddr + req_size);
|
||||
result->resp_vaddr = (void*)((uintptr_t)result->mem_vaddr + mem_size);
|
||||
result->resp_paddr = (void*)((uintptr_t)result->mem_paddr + mem_size);
|
||||
memcpy(result->req_vaddr, req_ptr, req_size);
|
||||
memcpy(result->mem_vaddr, mem_ptr, mem_size);
|
||||
memcpy(result->resp_vaddr, resp_ptr, resp_size);
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif //_KERNEL_DRIVERS_VIRTIO_VIRTIO_H
|
||||
Reference in New Issue
Block a user