summaryrefslogtreecommitdiff
path: root/src/arch/x86_common
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/arch/x86_common/acpi.c13
-rw-r--r--src/arch/x86_common/drivers/bochs.c (renamed from src/arch/amd64/drivers/bochs.c)3
-rw-r--r--src/arch/x86_common/drivers/pci.c57
-rw-r--r--src/arch/x86_common/drivers/pic.c (renamed from src/arch/amd64/drivers/pic.c)4
-rw-r--r--src/arch/x86_common/drivers/serial.c (renamed from src/arch/amd64/drivers/serial.c)3
-rw-r--r--src/arch/x86_common/include/bindings.h (renamed from src/arch/amd64/bindings.h)0
-rw-r--r--src/arch/x86_common/include/mboot.h (renamed from src/arch/amd64/mboot.h)0
-rw-r--r--src/arch/x86_common/include/pic.h (renamed from src/arch/amd64/drivers/pic.h)0
-rw-r--r--src/arch/x86_common/mboot.c (renamed from src/arch/amd64/mboot.c)3
9 files changed, 75 insertions, 8 deletions
diff --git a/src/arch/x86_common/acpi.c b/src/arch/x86_common/acpi.c
new file mode 100644
index 0000000..2392185
--- /dev/null
+++ b/src/arch/x86_common/acpi.c
@@ -0,0 +1,13 @@
+#include <bindings.h>
+
+#define ACPI_INTERNAL
+#include <sys/acpi.h>
+
+void acpi_sys_enable(struct acpi_state *state) {
+ outb(state->fadt->smi_command_port, state->fadt->acpi_enable);
+}
+
+int acpi_sys_shutdown(struct acpi_state *state) {
+ outw((unsigned int) state->fadt->pm1_a_control_block, state->SLP_TYPb | state->SLP_EN);
+ return -1;
+}
diff --git a/src/arch/amd64/drivers/bochs.c b/src/arch/x86_common/drivers/bochs.c
index b3908f9..8e9ca2b 100644
--- a/src/arch/amd64/drivers/bochs.c
+++ b/src/arch/x86_common/drivers/bochs.c
@@ -4,8 +4,7 @@
#include <panic.h>
#include <pci.h>
#include <bochs.h>
-
-#include "../bindings.h"
+#include <bindings.h>
#define INDEX 0x1CE
#define DATA 0x1CF
diff --git a/src/arch/x86_common/drivers/pci.c b/src/arch/x86_common/drivers/pci.c
new file mode 100644
index 0000000..579562a
--- /dev/null
+++ b/src/arch/x86_common/drivers/pci.c
@@ -0,0 +1,57 @@
+#include <pci.h>
+#include <bindings.h>
+
+#define PCI_INTERNAL
+#include <sys/pci.h>
+
+#define CONF_ADDR 0xCF8
+#define CONF_DATA 0xCFC
+
+uint32_t pci_sys_rcfg_d(struct pci_device dev, uint8_t offset) {
+ uint32_t addr = 0x80000000;
+ addr |= ((uint32_t)dev.bus) << 16;
+ addr |= ((uint32_t)dev.device) << 11;
+ addr |= ((uint32_t)dev.function) << 8;
+ addr |= offset & 0xFC;
+
+ outl(CONF_ADDR, addr);
+ uint32_t in = inl(CONF_DATA);
+ return in;
+}
+
+uint16_t pci_sys_rcfg_w(struct pci_device dev, uint8_t offset) {
+ uint32_t dword = pci_sys_rcfg_d(dev, offset);
+ return (uint16_t)((dword >> ((offset & 2) * 8)) & 0xFFFF);
+}
+
+uint8_t pci_sys_rcfg_b(struct pci_device dev, uint8_t offset) {
+ uint32_t dword = pci_sys_rcfg_d(dev, offset);
+ return (uint8_t)((dword >> ((offset & 3) * 8)) & 0xFF);
+}
+
+void pci_sys_wcfg_d(struct pci_device dev, uint8_t offset, uint32_t dword) {
+ uint32_t addr = 0x80000000;
+ addr |= ((uint32_t)dev.bus) << 16;
+ addr |= ((uint32_t)dev.device) << 11;
+ addr |= ((uint32_t)dev.function) << 8;
+ addr |= offset & 0xFC;
+
+ outl(CONF_ADDR, addr);
+ outl(CONF_DATA, dword);
+}
+
+void pci_sys_wcfg_w(struct pci_device dev, uint8_t offset, uint16_t word) {
+ size_t shift = (offset & 2) * 8;
+ uint32_t dword = pci_sys_rcfg_d(dev, offset);
+ dword &= ~(0xFFFF << shift);
+ dword |= word << shift;
+ pci_sys_wcfg_d(dev, offset, dword);
+}
+
+void pci_sys_wcfg_b(struct pci_device dev, uint8_t offset, uint8_t byte) {
+ size_t shift = (offset & 3) * 8;
+ uint32_t dword = pci_sys_rcfg_d(dev, offset);
+ dword &= ~(0xFF << shift);
+ dword |= byte << shift;
+ pci_sys_wcfg_d(dev, offset, dword);
+}
diff --git a/src/arch/amd64/drivers/pic.c b/src/arch/x86_common/drivers/pic.c
index be7716f..d911648 100644
--- a/src/arch/amd64/drivers/pic.c
+++ b/src/arch/x86_common/drivers/pic.c
@@ -1,5 +1,5 @@
-#include "../bindings.h"
-#include "pic.h"
+#include <bindings.h>
+#include <pic.h>
#define PIC1 0x20 /* IO base address for master PIC */
#define PIC2 0xA0 /* IO base address for slave PIC */
diff --git a/src/arch/amd64/drivers/serial.c b/src/arch/x86_common/drivers/serial.c
index b9e351e..255f8fc 100644
--- a/src/arch/amd64/drivers/serial.c
+++ b/src/arch/x86_common/drivers/serial.c
@@ -1,6 +1,5 @@
#include <serial.h>
-
-#include "../bindings.h"
+#include <bindings.h>
#define PORT 0x3F8
diff --git a/src/arch/amd64/bindings.h b/src/arch/x86_common/include/bindings.h
index 9406774..9406774 100644
--- a/src/arch/amd64/bindings.h
+++ b/src/arch/x86_common/include/bindings.h
diff --git a/src/arch/amd64/mboot.h b/src/arch/x86_common/include/mboot.h
index d1ca1a0..d1ca1a0 100644
--- a/src/arch/amd64/mboot.h
+++ b/src/arch/x86_common/include/mboot.h
diff --git a/src/arch/amd64/drivers/pic.h b/src/arch/x86_common/include/pic.h
index 2a4670e..2a4670e 100644
--- a/src/arch/amd64/drivers/pic.h
+++ b/src/arch/x86_common/include/pic.h
diff --git a/src/arch/amd64/mboot.c b/src/arch/x86_common/mboot.c
index 9fd7fc2..db82b9d 100644
--- a/src/arch/amd64/mboot.c
+++ b/src/arch/x86_common/mboot.c
@@ -2,8 +2,7 @@
#include <lib.h>
#include <stdint.h>
#include <panic.h>
-
-#include "mboot.h"
+#include <mboot.h>
#define MBOOT_HEADER_MAGIC 0x36D76289