Skip to content

Commit

Permalink
implemented support for hashtables, changed the collection implementa…
Browse files Browse the repository at this point in the history
…tion a bit, updated usage
  • Loading branch information
Meulengracht committed Nov 4, 2018
1 parent 0931f89 commit d4f8742
Show file tree
Hide file tree
Showing 45 changed files with 497 additions and 633 deletions.
44 changes: 19 additions & 25 deletions kernel/acpi/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,11 +474,9 @@ AcpiDeviceIrqRoutingCallback(
ACPI_RESOURCE *Resource,
void *Context)
{
// Variables
IrqResource_t *IrqResource = NULL;
DataKey_t pKey;
IrqResource_t* IrqResource = NULL;
DataKey_t Key = { 0 };

// Debug
TRACE("AcpiDeviceIrqRoutingCallback(Type %u)", Resource->Type);

// Sanitize the type of resource
Expand All @@ -488,7 +486,6 @@ AcpiDeviceIrqRoutingCallback(

// Initiate values
IrqResource = (IrqResource_t*)Context;
pKey.Value = 0;

// Right now we are just looking for Irq's
if (Resource->Type == ACPI_RESOURCE_TYPE_IRQ) {
Expand Down Expand Up @@ -532,7 +529,7 @@ AcpiDeviceIrqRoutingCallback(
}
else {
// Append to list of irqs
CollectionAppend(IrqResource->IrqList, CollectionCreateNode(pKey, RoutingEntry));
CollectionAppend(IrqResource->IrqList, CollectionCreateNode(Key, RoutingEntry));
}
}
}
Expand Down Expand Up @@ -577,7 +574,7 @@ AcpiDeviceIrqRoutingCallback(
}
else {
// Append to list of irqs
CollectionAppend(IrqResource->IrqList, CollectionCreateNode(pKey, RoutingEntry));
CollectionAppend(IrqResource->IrqList, CollectionCreateNode(Key, RoutingEntry));
}
}
}
Expand Down Expand Up @@ -741,15 +738,12 @@ ACPI_STATUS
AcpiDeviceGetIrqRoutings(
_In_ AcpiDevice_t *Device)
{
// Variables
ACPI_PCI_ROUTING_TABLE *PciTable = NULL;
PciRoutings_t *Table = NULL;
ACPI_STATUS Status;
int i;

// Buffers
IrqResource_t IrqResource;
ACPI_BUFFER aBuff;
ACPI_PCI_ROUTING_TABLE* PciTable = NULL;
PciRoutings_t* Table = NULL;
ACPI_STATUS Status;
IrqResource_t IrqResource;
ACPI_BUFFER aBuff;
int i;

// Debug
TRACE("AcpiDeviceGetIrqRoutings()");
Expand Down Expand Up @@ -787,8 +781,8 @@ AcpiDeviceGetIrqRoutings(
ACPI_HANDLE SourceHandle = NULL;
unsigned InterruptIndex = 0;
unsigned DeviceIndex = 0;
CollectionItem_t *Node = NULL;
DataKey_t Key;
CollectionItem_t* Node = NULL;
DataKey_t Key = { 0 };

// Convert the addresses
DeviceIndex = (unsigned)((PciTable->Address >> 16) & 0xFFFF);
Expand All @@ -806,12 +800,11 @@ AcpiDeviceGetIrqRoutings(

// Allocate a new entry and store information
RoutingEntry = (PciRoutingEntry_t*)kmalloc(sizeof(PciRoutingEntry_t));
RoutingEntry->AcType = ACPI_RESOURCE_TYPE_IRQ;
RoutingEntry->Irq = (int)PciTable->SourceIndex;
RoutingEntry->Polarity = ACPI_ACTIVE_LOW;
RoutingEntry->Trigger = ACPI_LEVEL_SENSITIVE;
RoutingEntry->Fixed = 1;
Key.Value = 0;
RoutingEntry->AcType = ACPI_RESOURCE_TYPE_IRQ;
RoutingEntry->Irq = (int)PciTable->SourceIndex;
RoutingEntry->Polarity = ACPI_ACTIVE_LOW;
RoutingEntry->Trigger = ACPI_LEVEL_SENSITIVE;
RoutingEntry->Fixed = 1;

// Save interrupt
CollectionAppend(Table->InterruptEntries[InterruptIndex],
Expand All @@ -822,7 +815,8 @@ AcpiDeviceGetIrqRoutings(

// Ok, so we have a valid handle, lets see if we already have
// the handle cached in memory
Key.String = &PciTable->Source[0];
Key.Value.String.Pointer = &PciTable->Source[0];
Key.Value.String.Length = strlen(&PciTable->Source[0]);
Node = CollectionGetNodeByKey(Table->Sources, Key, 0);
if (Node != NULL) {
Source = (PciRoutingSource_t*)Node->Data;
Expand Down
9 changes: 2 additions & 7 deletions kernel/acpi/interrupts.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,8 @@ AcpiDeriveInterrupt(
_In_ int Pin,
_Out_ Flags_t* AcpiConform)
{
// Variables
AcpiDevice_t *Dev = NULL;
DataKey_t iKey;

// Calculate routing index
unsigned rIndex = (Device * 4) + (Pin - 1);
iKey.Value = 0;
AcpiDevice_t* Dev;
unsigned rIndex = (Device * 4) + (Pin - 1);

// Trace
TRACE("AcpiDeriveInterrupt(Bus %u, Device %u, Pin %i)", Bus, Device, Pin);
Expand Down
12 changes: 5 additions & 7 deletions kernel/acpi/scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@ AcpiDevice_t*
AcpiDeviceLookupBusRoutings(
_In_ int Bus)
{
// Variables
AcpiDevice_t *Dev = NULL;
DataKey_t Key;
int Index = 0;
AcpiDevice_t* Dev;
DataKey_t Key = { .Value.Integer = ACPI_BUS_ROOT_BRIDGE };
int Index = 0;

// Loop through buses
while (1) {
Key.Value = ACPI_BUS_ROOT_BRIDGE;
Dev = (AcpiDevice_t*)CollectionGetNodeByKey(&PciToAcpiDevices, Key, Index);
Dev = (AcpiDevice_t*)CollectionGetNodeByKey(&PciToAcpiDevices, Key, Index);
if (Dev == NULL) {
break;
}
Expand Down Expand Up @@ -214,7 +212,7 @@ AcpiDeviceCreate(
}

// Add the device to device-list
Device->Header.Key.Value = Device->Type;
Device->Header.Key.Value.Integer = Device->Type;
return CollectionAppend(&PciToAcpiDevices, &Device->Header);
}

Expand Down
155 changes: 33 additions & 122 deletions kernel/arch/x86/x32/portio.s
Original file line number Diff line number Diff line change
Expand Up @@ -33,145 +33,56 @@ global _outl
; uint8_t inb(uint16_t port)
; Recieves a byte from a port
_inb:
; Setup frame
push ebp
mov ebp, esp

; Save stuff
push edx

; Get byte
xor al, al
xor edx, edx
mov dx, [ebp + 8]
in al, dx

; Restore
pop edx

; Leave frame
pop ebp
ret
xor eax, eax
xor edx, edx
mov dx, word [esp + 4]
in al, dx
ret

; uint16_t inw(uint16_t port)
; Recieves a word from a port
_inw:
; Setup frame
push ebp
mov ebp, esp

; Save stuff
push edx

; Get word
xor ax, ax
xor edx, edx
mov dx, [ebp + 8]
in ax, dx

; Restore
pop edx

; Leave
pop ebp
ret
xor eax, eax
xor edx, edx
mov dx, word [esp + 4]
in ax, dx
ret

; uint32_t inl(uint16_t port)
; Recieves a long from a port
_inl:
; Setup frame
push ebp
mov ebp, esp

; Save stuff
push edx

; Get dword
xor eax, eax
xor edx, edx
mov dx, [ebp + 8]
in eax, dx

; Restore
pop edx

; Leave
pop ebp
ret
xor eax, eax
xor edx, edx
mov dx, word [esp + 4]
in eax, dx
ret

; void outb(uint16_t port, uint8_t data)
; Sends a byte to a port
_outb:
; Setup frame
push ebp
mov ebp, esp

; Save stuff
push eax
push edx

; Get data
xor eax, eax
xor edx, edx
mov dx, [ebp + 8]
mov al, [ebp + 12]
out dx, al

; Restore
pop edx
pop eax

; Leave
pop ebp
ret
xor eax, eax
xor edx, edx
mov dx, word [esp + 4]
mov al, byte [esp + 8]
out dx, al
ret

; void outw(uint16_t port, uint16_t data)
; Sends a word to a port
_outw:
; Stack Frame
push ebp
mov ebp, esp

; Save stuff
push eax
push edx

; Get data
xor eax, eax
xor edx, edx
mov dx, [ebp + 8]
mov ax, [ebp + 12]
out dx, ax

; Restore
pop edx
pop eax

; Release stack frame
pop ebp
ret
xor eax, eax
xor edx, edx
mov dx, word [esp + 4]
mov ax, word [esp + 8]
out dx, ax
ret

; void outl(uint16_t port, uint32_t data)
; Sends a long to a port
_outl:
; Stack Frame
push ebp
mov ebp, esp

; Save stuff
push eax
push edx

; Get data
xor edx, edx
mov dx, [ebp + 8]
mov eax, [ebp + 12]
out dx, eax

; Restore
pop edx
pop eax

; Release stack frame
pop ebp
ret
xor eax, eax
xor edx, edx
mov dx, word [esp + 4]
mov eax, dword [esp + 8]
out dx, eax
ret
Loading

0 comments on commit d4f8742

Please sign in to comment.