1 | // SPDX-License-Identifier: GPL-3.0-or-later |
2 | |
3 | #include "mos/x86/devices/serial_driver.h" |
4 | |
5 | #include "mos/device/serial.h" |
6 | #include "mos/x86/devices/port.h" |
7 | |
8 | static u8 serial_read_data(serial_device_t *device) |
9 | { |
10 | x86_com_port_t port = (x86_com_port_t) (ptr_t) device->driver_data; |
11 | return port_inb(port); |
12 | } |
13 | |
14 | static void serial_write_data(serial_device_t *device, u8 data) |
15 | { |
16 | x86_com_port_t port = (x86_com_port_t) (ptr_t) device->driver_data; |
17 | port_outb(port, value: data); |
18 | } |
19 | |
20 | static u8 serial_read_register(serial_device_t *device, serial_register_t reg) |
21 | { |
22 | x86_com_port_t port = (x86_com_port_t) (ptr_t) device->driver_data; |
23 | return port_inb(port: port + reg); |
24 | } |
25 | |
26 | static void serial_write_register(serial_device_t *device, serial_register_t reg, u8 data) |
27 | { |
28 | x86_com_port_t port = (x86_com_port_t) (ptr_t) device->driver_data; |
29 | port_outb(port: port + reg, value: data); |
30 | } |
31 | |
32 | const serial_driver_t x86_serial_driver = { |
33 | .read_data = serial_read_data, |
34 | .write_data = serial_write_data, |
35 | .read_register = serial_read_register, |
36 | .write_register = serial_write_register, |
37 | }; |
38 | |