aboutsummaryrefslogtreecommitdiff
path: root/kernel/drivers
diff options
context:
space:
mode:
authorMarvin Borner2021-05-23 14:30:07 +0200
committerMarvin Borner2021-05-23 14:34:52 +0200
commit33fd97e19a12535c02b1cf6804cb854a279e040c (patch)
tree0ea00a9b60b35e42830eb3b13887fea2d356d655 /kernel/drivers
parent0bf64a113f3d3baa110b362fd6a215ef29182671 (diff)
Cleanup, linting, formatting
Diffstat (limited to 'kernel/drivers')
-rw-r--r--kernel/drivers/acpi.c12
-rw-r--r--kernel/drivers/cpu.c2
-rw-r--r--kernel/drivers/interrupts.c4
-rw-r--r--kernel/drivers/mbr.c2
-rw-r--r--kernel/drivers/pci.c4
-rw-r--r--kernel/drivers/ps2/keyboard.c6
-rw-r--r--kernel/drivers/ps2/mouse.c4
-rw-r--r--kernel/drivers/ps2/ps2.c4
-rw-r--r--kernel/drivers/rtc.c6
-rw-r--r--kernel/drivers/rtl8139.c177
-rw-r--r--kernel/drivers/serial.c2
-rw-r--r--kernel/drivers/timer.c6
-rw-r--r--kernel/drivers/vmware.c4
13 files changed, 28 insertions, 205 deletions
diff --git a/kernel/drivers/acpi.c b/kernel/drivers/acpi.c
index 6860a43..13c132c 100644
--- a/kernel/drivers/acpi.c
+++ b/kernel/drivers/acpi.c
@@ -1,13 +1,13 @@
// MIT License, Copyright (c) 2020 Marvin Borner
-#include <drivers/acpi.h>
#include <assert.h>
-#include <drivers/cpu.h>
#include <def.h>
+#include <drivers/acpi.h>
+#include <drivers/cpu.h>
#include <mem.h>
#include <print.h>
-int check_sdt(struct sdt_header *header)
+static int check_sdt(struct sdt_header *header)
{
u8 sum = 0;
@@ -17,7 +17,7 @@ int check_sdt(struct sdt_header *header)
return sum == 0;
}
-int check_sdp(struct sdp_header *header)
+static int check_sdp(struct sdp_header *header)
{
u8 sum = 0;
@@ -27,7 +27,7 @@ int check_sdp(struct sdp_header *header)
return sum == 0;
}
-struct rsdp *find_rsdp(void)
+static struct rsdp *find_rsdp(void)
{
// Main BIOS area
for (int i = 0xe0000; i < 0xfffff; i++) {
@@ -45,7 +45,7 @@ struct rsdp *find_rsdp(void)
return NULL;
}
-void *find_sdt(struct rsdt *rsdt, const char *signature)
+static void *find_sdt(struct rsdt *rsdt, const char *signature)
{
u32 entries = (rsdt->header.length - sizeof(rsdt->header)) / 4;
diff --git a/kernel/drivers/cpu.c b/kernel/drivers/cpu.c
index 8927d1d..8694fc2 100644
--- a/kernel/drivers/cpu.c
+++ b/kernel/drivers/cpu.c
@@ -2,8 +2,8 @@
// This file is a wrapper around some CPU asm calls
#include <assert.h>
-#include <drivers/cpu.h>
#include <def.h>
+#include <drivers/cpu.h>
#include <mem.h>
#include <print.h>
diff --git a/kernel/drivers/interrupts.c b/kernel/drivers/interrupts.c
index e9ab0ce..39a59a0 100644
--- a/kernel/drivers/interrupts.c
+++ b/kernel/drivers/interrupts.c
@@ -2,14 +2,14 @@
// TODO: Remove some magic numbers
#include <assert.h>
-#include <drivers/cpu.h>
#include <def.h>
+#include <drivers/cpu.h>
#include <drivers/interrupts.h>
+#include <drivers/serial.h>
#include <mem.h>
#include <mm.h>
#include <print.h>
#include <proc.h>
-#include <drivers/serial.h>
/**
* IDT
diff --git a/kernel/drivers/mbr.c b/kernel/drivers/mbr.c
index c9eba15..d5f7a40 100644
--- a/kernel/drivers/mbr.c
+++ b/kernel/drivers/mbr.c
@@ -1,9 +1,9 @@
// MIT License, Copyright (c) 2021 Marvin Borner
#include <def.h>
-#include <fs.h>
#include <drivers/ide.h>
#include <drivers/mbr.h>
+#include <fs.h>
#include <mem.h>
#include <print.h>
#include <str.h>
diff --git a/kernel/drivers/pci.c b/kernel/drivers/pci.c
index 55806c2..0aab8e5 100644
--- a/kernel/drivers/pci.c
+++ b/kernel/drivers/pci.c
@@ -2,10 +2,10 @@
// Uses parts of the ToAruOS Project, released under the terms of the NCSA
// Copyright (C) 2011-2018 K. Lange
-#include <drivers/cpu.h>
#include <def.h>
-#include <mem.h>
+#include <drivers/cpu.h>
#include <drivers/pci.h>
+#include <mem.h>
CLEAR void pci_write_field(u32 device, int field, u32 value)
{
diff --git a/kernel/drivers/ps2/keyboard.c b/kernel/drivers/ps2/keyboard.c
index bddb280..bf1a520 100644
--- a/kernel/drivers/ps2/keyboard.c
+++ b/kernel/drivers/ps2/keyboard.c
@@ -1,14 +1,14 @@
// MIT License, Copyright (c) 2020 Marvin Borner
-#include <drivers/cpu.h>
#include <def.h>
-#include <errno.h>
+#include <drivers/cpu.h>
#include <drivers/interrupts.h>
+#include <drivers/ps2.h>
+#include <errno.h>
#include <io.h>
#include <mem.h>
#include <print.h>
#include <proc.h>
-#include <drivers/ps2.h>
#include <stack.h>
#include <str.h>
#include <sys.h>
diff --git a/kernel/drivers/ps2/mouse.c b/kernel/drivers/ps2/mouse.c
index 2942e34..680183d 100644
--- a/kernel/drivers/ps2/mouse.c
+++ b/kernel/drivers/ps2/mouse.c
@@ -2,13 +2,13 @@
#include <assert.h>
#include <drivers/cpu.h>
-#include <errno.h>
#include <drivers/interrupts.h>
+#include <drivers/ps2.h>
+#include <errno.h>
#include <io.h>
#include <mem.h>
#include <print.h>
#include <proc.h>
-#include <drivers/ps2.h>
#include <stack.h>
#include <str.h>
#include <sys.h>
diff --git a/kernel/drivers/ps2/ps2.c b/kernel/drivers/ps2/ps2.c
index f8d849b..0206892 100644
--- a/kernel/drivers/ps2/ps2.c
+++ b/kernel/drivers/ps2/ps2.c
@@ -1,10 +1,10 @@
// MIT License, Copyright (c) 2021 Marvin Borner
#include <assert.h>
-#include <drivers/cpu.h>
#include <def.h>
-#include <print.h>
+#include <drivers/cpu.h>
#include <drivers/ps2.h>
+#include <print.h>
#define PS2_TIMEOUT 100
diff --git a/kernel/drivers/rtc.c b/kernel/drivers/rtc.c
index 63d9461..b67829e 100644
--- a/kernel/drivers/rtc.c
+++ b/kernel/drivers/rtc.c
@@ -1,12 +1,12 @@
// MIT License, Copyright (c) 2021 Marvin Borner
-#include <drivers/cpu.h>
#include <def.h>
+#include <drivers/cpu.h>
+#include <drivers/rtc.h>
+#include <drivers/timer.h>
#include <fs.h>
#include <mem.h>
-#include <drivers/rtc.h>
#include <str.h>
-#include <drivers/timer.h>
static u8 rtc_busy(void)
{
diff --git a/kernel/drivers/rtl8139.c b/kernel/drivers/rtl8139.c
deleted file mode 100644
index 8e7bc88..0000000
--- a/kernel/drivers/rtl8139.c
+++ /dev/null
@@ -1,177 +0,0 @@
-// MIT License, Copyright (c) 2020 Marvin Borner
-// Uses parts of the ToAruOS Project, released under the terms of the NCSA
-// Copyright (C) 2011-2018 K. Lange
-
-#include <def.h>
-#include <drivers/cpu.h>
-#include <drivers/interrupts.h>
-#include <drivers/pci.h>
-#include <drivers/rtl8139.h>
-#include <mem.h>
-#include <net.h>
-#include <print.h>
-
-static int rtl_irq = 0;
-static u8 mac[6] = { 0 };
-static u8 *last_packet = NULL;
-static u8 *rtl_rx_buffer = NULL;
-static u32 rtl_device_pci = 0;
-static u32 rtl_iobase = 0;
-static u32 cur_rx = 0;
-
-u8 *rtl8139_get_mac(void)
-{
- if (!rtl_device_pci)
- return NULL;
-
- return mac;
-}
-
-static void rtl8139_receive_packet(void)
-{
- while ((inb(rtl_iobase + RTL_PORT_CMD) & 0x01) == 0) {
- int offset = cur_rx % 0x2000;
-
- u32 *buf_start = (u32 *)((u32)rtl_rx_buffer + offset);
- u32 rx_status = buf_start[0];
- u32 rx_size = rx_status >> 16;
-
- if (rx_status & (0x0020 | 0x0010 | 0x0004 | 0x0002)) {
- print("RX Error\n");
- } else {
- u8 *buf_8 = (u8 *)&(buf_start[1]);
-
- last_packet = malloc(rx_size);
-
- u32 packet_end = (u32)buf_8 + rx_size;
- if (packet_end > (u32)rtl_rx_buffer + 0x2000) {
- u32 s = ((u32)rtl_rx_buffer + 0x2000) - (u32)buf_8;
- memcpy(last_packet, buf_8, s);
- memcpy((void *)((u32)last_packet + s), rtl_rx_buffer, rx_size - s);
- } else {
- memcpy(last_packet, buf_8, rx_size);
- }
-
- u16 *t = (u16 *)(rtl_rx_buffer + cur_rx);
- ethernet_handle_packet((struct ethernet_packet *)last_packet, *(t + 1));
- }
-
- cur_rx = (cur_rx + rx_size + 4 + 3) & ~3;
- outw(rtl_iobase + RTL_PORT_RXPTR, cur_rx - 16);
- }
-}
-
-static u8 tsad_array[4] = { 0x20, 0x24, 0x28, 0x2C };
-static u8 tsd_array[4] = { 0x10, 0x14, 0x18, 0x1C };
-static u8 tx_current = 0;
-void rtl8139_send_packet(void *data, u32 len)
-{
- if (!rtl_device_pci)
- return;
-
- outl(rtl_iobase + tsad_array[tx_current], (u32)data);
- outl(rtl_iobase + tsd_array[tx_current++], len);
- if (tx_current > 3)
- tx_current = 0;
-}
-
-static void rtl8139_find(u32 device, u16 vendor_id, u16 device_id, void *extra)
-{
- if ((vendor_id == 0x10ec) && (device_id == 0x8139))
- *((u32 *)extra) = device;
-}
-
-static void rtl8139_irq_handler(struct regs *r)
-{
- UNUSED(r);
- u16 status = inw(rtl_iobase + RTL_PORT_ISR);
- if (!status)
- return;
- outw(rtl_iobase + RTL_PORT_ISR, status);
-
- if (status & 0x01 || status & 0x02)
- rtl8139_receive_packet();
-}
-
-static void rtl8139_init(void)
-{
- if (!rtl_device_pci)
- return;
-
- u16 command_reg = (u16)pci_read_field(rtl_device_pci, PCI_COMMAND, 4);
- if ((command_reg & (1 << 2)) == 0) {
- command_reg |= (1 << 2);
- pci_write_field(rtl_device_pci, PCI_COMMAND, command_reg);
- }
-
- rtl_irq = pci_get_interrupt(rtl_device_pci);
- irq_install_handler(rtl_irq, rtl8139_irq_handler);
-
- u32 rtl_bar0 = pci_read_field(rtl_device_pci, PCI_BAR0, 4);
- /* u32 rtl_bar1 = pci_read_field(rtl_device_pci, PCI_BAR1, 4); */
- rtl_iobase = 0;
-
- if (rtl_bar0 & 0x00000001)
- rtl_iobase = rtl_bar0 & 0xFFFFFFFC;
-
- // Get mac address
- for (int i = 0; i < 6; ++i)
- mac[i] = inb(rtl_iobase + RTL_PORT_MAC + i);
- printf("Mac address: %x:%x:%x:%x:%x:%x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
-
- // Activate
- outb(rtl_iobase + RTL_PORT_CONFIG, 0x0);
-
- // Reset
- outb((u16)(rtl_iobase + RTL_PORT_CMD), 0x10);
- while ((inb(rtl_iobase + RTL_PORT_CMD) & 0x10) != 0)
- ;
-
- // Set receive buffer
- rtl_rx_buffer = (u8 *)malloc(0x3000);
- memset(rtl_rx_buffer, 0, 0x3000);
- outl(rtl_iobase + RTL_PORT_RBSTART, (u32)rtl_rx_buffer);
-
- // Enable IRQs
- outw(rtl_iobase + RTL_PORT_IMR, 0x8000 | /* PCI error */
- 0x4000 | /* PCS timeout */
- 0x40 | /* Rx FIFO over */
- 0x20 | /* Rx underrun */
- 0x10 | /* Rx overflow */
- 0x08 | /* Tx error */
- 0x04 | /* Tx okay */
- 0x02 | /* Rx error */
- 0x01 /* Rx okay */
- );
-
- // Configure transmit
- outl(rtl_iobase + RTL_PORT_TCR, 0);
-
- // Configure receive
- outl(rtl_iobase + RTL_PORT_RCR, (0) | /* 8K receive */
- 0x08 | /* broadcast */
- 0x01 /* all physical */
- );
-
- // Enable receive and transmit
- outb(rtl_iobase + RTL_PORT_CMD, 0x08 | 0x04);
-
- // Reset rx statistics
- outl(rtl_iobase + RTL_PORT_RXMISS, 0);
-}
-
-int rtl8139_installed(void)
-{
- return rtl_device_pci != 0;
-}
-
-int rtl8139_install(void)
-{
- pci_scan(&rtl8139_find, -1, &rtl_device_pci);
-
- if (rtl_device_pci) {
- print("Found rtl8139 card\n");
- rtl8139_init();
- }
- return rtl_device_pci;
-}
diff --git a/kernel/drivers/serial.c b/kernel/drivers/serial.c
index 95ac02d..281772d 100644
--- a/kernel/drivers/serial.c
+++ b/kernel/drivers/serial.c
@@ -1,8 +1,8 @@
// MIT License, Copyright (c) 2020 Marvin Borner
#include <assert.h>
-#include <drivers/cpu.h>
#include <def.h>
+#include <drivers/cpu.h>
#include <drivers/serial.h>
#include <str.h>
diff --git a/kernel/drivers/timer.c b/kernel/drivers/timer.c
index c586088..3ddc229 100644
--- a/kernel/drivers/timer.c
+++ b/kernel/drivers/timer.c
@@ -1,13 +1,13 @@
// MIT License, Copyright (c) 2020 Marvin Borner
-#include <drivers/cpu.h>
#include <def.h>
+#include <drivers/cpu.h>
#include <drivers/interrupts.h>
+#include <drivers/rtc.h>
+#include <drivers/timer.h>
#include <io.h>
#include <mem.h>
#include <proc.h>
-#include <drivers/rtc.h>
-#include <drivers/timer.h>
static u32 timer_ticks = 0;
PROTECTED static u8 call_scheduler = 0;
diff --git a/kernel/drivers/vmware.c b/kernel/drivers/vmware.c
index 6f95d02..169865f 100644
--- a/kernel/drivers/vmware.c
+++ b/kernel/drivers/vmware.c
@@ -3,12 +3,12 @@
#include <def.h>
#include <drivers/interrupts.h>
+#include <drivers/ps2.h>
+#include <drivers/vmware.h>
#include <io.h>
#include <mem.h>
#include <print.h>
-#include <drivers/ps2.h>
#include <stack.h>
-#include <drivers/vmware.h>
#define VMWARE_CMD_VERSION 0x0a