Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ia32: add support for ACPI #630

Open
wants to merge 2 commits into
base: adamgreloch/RTOS-937
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hal/ia32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

include hal/tlb/Makefile

OBJS += $(addprefix $(PREFIX_O)hal/ia32/, _init.o _exceptions.o _interrupts.o spinlock.o exceptions.o interrupts.o cpu.o pmap.o timer.o hal.o string.o pci.o init.o)
OBJS += $(addprefix $(PREFIX_O)hal/ia32/, _init.o _exceptions.o _interrupts.o spinlock.o exceptions.o interrupts.o cpu.o pmap.o timer.o hal.o string.o pci.o init.o acpi.o)
CFLAGS += -Ihal/ia32

ifeq ($(CONSOLE), vga)
Expand Down
8 changes: 8 additions & 0 deletions hal/ia32/_interrupts.S
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ INTERRUPT(_interrupts_irq12, 12, interrupts_dispatchIRQ)
INTERRUPT(_interrupts_irq13, 13, interrupts_dispatchIRQ)
INTERRUPT(_interrupts_irq14, 14, interrupts_dispatchIRQ)
INTERRUPT(_interrupts_irq15, 15, interrupts_dispatchIRQ)
INTERRUPT(_interrupts_irq16, 16, interrupts_dispatchIRQ)
INTERRUPT(_interrupts_irq17, 17, interrupts_dispatchIRQ)
INTERRUPT(_interrupts_irq18, 18, interrupts_dispatchIRQ)
INTERRUPT(_interrupts_irq19, 19, interrupts_dispatchIRQ)
INTERRUPT(_interrupts_irq20, 20, interrupts_dispatchIRQ)
INTERRUPT(_interrupts_irq21, 21, interrupts_dispatchIRQ)
INTERRUPT(_interrupts_irq22, 22, interrupts_dispatchIRQ)
INTERRUPT(_interrupts_irq23, 23, interrupts_dispatchIRQ)
INTERRUPT(_interrupts_unexpected, 255, _interrupts_unexpected)


Expand Down
31 changes: 31 additions & 0 deletions hal/ia32/acpi.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Phoenix-RTOS
*
* Operating system kernel
*
* ACPI kernel-userspace interface
*
* Copyright 2025 Phoenix Systems
* Author: Adam Greloch
*
* %LICENSE%
*/

#include "include/errno.h"
#include "include/arch/ia32/ia32.h"
#include "halsyspage.h"


int hal_acpiGet(acpi_var_t var, int *value)
{
switch (var) {
case acpi_rsdpAddr:
if (syspage->hs.acpi_version != ACPI_RSDP) {
return -EINVAL;
}
*value = syspage->hs.rsdp;
return EOK;
}

return -EINVAL;
}
23 changes: 23 additions & 0 deletions hal/ia32/acpi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Phoenix-RTOS
*
* Operating system kernel
*
* ACPI kernel-userspace interface
*
* Copyright 2025 Phoenix Systems
* Author: Adam Greloch
*
* %LICENSE%
*/

#ifndef _HAL_ACPI_H_
#define _HAL_ACPI_H_

#include "include/arch/ia32/ia32.h"


extern int hal_acpiGet(acpi_var_t var, int *value);


#endif
7 changes: 7 additions & 0 deletions hal/ia32/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "hal/pmap.h"
#include "hal/hal.h"
#include "hal/tlb/tlb.h"
#include "acpi.h"
#include "pci.h"
#include "ia32.h"
#include "halsyspage.h"
Expand Down Expand Up @@ -548,6 +549,12 @@ int hal_platformctl(void *ptr)
platformctl_t *data = (platformctl_t *)ptr;

switch (data->type) {
case pctl_acpi:
if (data->action == pctl_get) {
return hal_acpiGet(data->acpi.var, &data->acpi.value);
}
break;

case pctl_pci:
if (data->action == pctl_get) {
return hal_pciGetDevice(&data->pci.id, &data->pci.dev, data->pci.caps);
Expand Down
41 changes: 38 additions & 3 deletions hal/ia32/interrupts.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ extern void _interrupts_irq12(void);
extern void _interrupts_irq13(void);
extern void _interrupts_irq14(void);
extern void _interrupts_irq15(void);
extern void _interrupts_irq16(void);
extern void _interrupts_irq17(void);
extern void _interrupts_irq18(void);
extern void _interrupts_irq19(void);
extern void _interrupts_irq20(void);
extern void _interrupts_irq21(void);
extern void _interrupts_irq22(void);
extern void _interrupts_irq23(void);

extern void _interrupts_unexpected(void);

Expand All @@ -55,7 +63,8 @@ extern void _interrupts_syscall(void);
extern void _interrupts_TLBShootdown(void);


#define SIZE_INTERRUPTS 16
#define ISA_INTERRUPTS 16
#define SIZE_INTERRUPTS 24


struct {
Expand Down Expand Up @@ -209,6 +218,20 @@ int interrupts_dispatchIRQ(unsigned int n, cpu_context_t *ctx)
}


static inline void _hal_ioapicUnmaskPCI(unsigned int n)
{
u32 high, low;

_hal_ioapicReadIRQ(interrupts_common.irqs[n].ioapic, n, &high, &low);

if ((low & IOAPIC_IRQ_MASK) != 0) {
/* PCI interrupts are active low level triggered */
low |= (IOAPIC_INTPOL | IOAPIC_TRIGGER);
_hal_ioapicWriteIRQ(interrupts_common.irqs[n].ioapic, n, high, low & ~IOAPIC_IRQ_MASK);
}
}


int hal_interruptsSetHandler(intr_handler_t *h)
{
spinlock_ctx_t sc;
Expand All @@ -219,6 +242,10 @@ int hal_interruptsSetHandler(intr_handler_t *h)

hal_spinlockSet(&interrupts_common.interrupts[h->n].spinlock, &sc);
HAL_LIST_ADD(&interrupts_common.interrupts[h->n].handler, h);
if (h->n >= ISA_INTERRUPTS) {
/* Assume IRQs above ISA_INTERRUPTS are PCI interrupts */
_hal_ioapicUnmaskPCI(h->n);
}
hal_spinlockClear(&interrupts_common.interrupts[h->n].spinlock, &sc);

return EOK;
Expand Down Expand Up @@ -429,8 +456,8 @@ static int _hal_ioapicInit(void)
}
}

/* Enable all IRQS */
for (i = 0; i < SIZE_INTERRUPTS; ++i) {
/* Enable all ISA IRQs */
for (i = 0; i < ISA_INTERRUPTS; ++i) {
_hal_ioapicReadIRQ(interrupts_common.irqs[i].ioapic, i, &high, &low);
_hal_ioapicWriteIRQ(interrupts_common.irqs[i].ioapic, i, high, low & ~IOAPIC_IRQ_MASK);
}
Expand Down Expand Up @@ -480,6 +507,14 @@ void _hal_interruptsInit(void)
_interrupts_setIDTEntry(INTERRUPTS_VECTOR_OFFSET + 13, _interrupts_irq13, flags);
_interrupts_setIDTEntry(INTERRUPTS_VECTOR_OFFSET + 14, _interrupts_irq14, flags);
_interrupts_setIDTEntry(INTERRUPTS_VECTOR_OFFSET + 15, _interrupts_irq15, flags);
_interrupts_setIDTEntry(INTERRUPTS_VECTOR_OFFSET + 16, _interrupts_irq16, flags);
_interrupts_setIDTEntry(INTERRUPTS_VECTOR_OFFSET + 17, _interrupts_irq17, flags);
_interrupts_setIDTEntry(INTERRUPTS_VECTOR_OFFSET + 18, _interrupts_irq18, flags);
_interrupts_setIDTEntry(INTERRUPTS_VECTOR_OFFSET + 19, _interrupts_irq19, flags);
_interrupts_setIDTEntry(INTERRUPTS_VECTOR_OFFSET + 20, _interrupts_irq20, flags);
_interrupts_setIDTEntry(INTERRUPTS_VECTOR_OFFSET + 21, _interrupts_irq21, flags);
_interrupts_setIDTEntry(INTERRUPTS_VECTOR_OFFSET + 22, _interrupts_irq22, flags);
_interrupts_setIDTEntry(INTERRUPTS_VECTOR_OFFSET + 23, _interrupts_irq23, flags);

for (k = 0; k < SIZE_INTERRUPTS; k++) {
hal_spinlockCreate(&interrupts_common.interrupts[k].spinlock, "interrupts_common.interrupts[].spinlock");
Expand Down
9 changes: 8 additions & 1 deletion include/arch/ia32/ia32.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ typedef struct {
} __attribute__((packed)) pci_dev_t;


typedef enum { acpi_rsdpAddr = 0 } acpi_var_t;

/* clang-format off */
typedef enum { pci_cfg_interruptdisable, pci_cfg_memoryspace, pci_cfg_busmaster} pci_cfg_t;
/* clang-format on */
Expand All @@ -80,10 +82,15 @@ typedef enum { pci_cfg_interruptdisable, pci_cfg_memoryspace, pci_cfg_busmaster}
typedef struct {
/* clang-format off */
enum { pctl_set = 0, pctl_get } action;
enum { pctl_pci = 0, pctl_pcicfg, pctl_usbownership, pctl_reboot, pctl_graphmode } type;
enum { pctl_pci = 0, pctl_acpi, pctl_pcicfg, pctl_usbownership, pctl_reboot, pctl_graphmode } type;
/* clang-format on */

union {
struct {
acpi_var_t var;
int value;
} acpi;

struct {
pci_id_t id;
pci_dev_t dev;
Expand Down
1 change: 1 addition & 0 deletions include/arch/ia32/syspage.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ typedef struct {

unsigned int ebda;
unsigned int acpi_version;
unsigned long rsdp; /* addr_t */
unsigned int localApicAddr;
unsigned long madt; /* addr_t */
unsigned int madtLength;
Expand Down