diff --git a/include/io/acpi.h b/include/io/acpi.h index 3363a8a..7421859 100644 --- a/include/io/acpi.h +++ b/include/io/acpi.h @@ -70,7 +70,7 @@ struct SDTHeader_t { uint creatorID; uint creatorRevision; uint sdtEntry; -}; +} __attribute__ ((packed)); // // GAS type, used by ACPI tables to inform about registers @@ -82,7 +82,7 @@ struct GenericAddressStructure uchar offset; uchar accessSize; ulong address; -}; +} __attribute__ ((packed)); // // ACPI table types id @@ -192,7 +192,7 @@ struct FADT_t struct GenericAddressStructure xPMTimerBlock; struct GenericAddressStructure xGPE0Block; struct GenericAddressStructure xGPE1Block; -}; +} __attribute__ ((packed)); //----------------------------------------------------------------------------// diff --git a/include/kernel.h b/include/kernel.h index 09084d9..a8430ae 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -59,6 +59,7 @@ typedef struct ISRFrame_t ISRFrame_t; typedef struct RSDPDescriptor_t RSDPDescriptor_t; typedef struct SDTHeader_t SDTHeader_t; typedef struct FADT_t FADT_t; +typedef struct MCFG_t MCFG_t; typedef struct MemoryMap_t MemoryMap_t; typedef struct MapEntry_t MapEntry_t; diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index d743926..03810c5 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -35,10 +35,14 @@ #include #include #include +#include #include #include +<<<<<<< HEAD #include #include +======= +>>>>>>> master // // Entry point of the Kaleid kernel @@ -86,7 +90,7 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg) // ACPI IoInitAcpi(); - // PCI + // PCI express IoInitPCI(); // Network diff --git a/kaleid/kernel/io/acpi.c b/kaleid/kernel/io/acpi.c index 6448fe0..bae24da 100644 --- a/kaleid/kernel/io/acpi.c +++ b/kaleid/kernel/io/acpi.c @@ -169,16 +169,14 @@ static inline void IoInitRXSDT(void) KeStartPanic("Invalid RSDT checksum : %d vs 0", checksum); if (IoACPIVersion == 1) { - DebugLog("ACPI Root System Table %s (%s) length %d [%p]\n", + DebugLog("ACPI Root System Table %s length %d [%p]\n", rxsdt->signature, - rxsdt->OEMID, rxsdt->length, rxsdt ); } else { - DebugLog("ACPI Extended System Table %s (%s) length %d [%p]\n", + DebugLog("ACPI Extended System Table %s length %d [%p]\n", rxsdt->signature, - rxsdt->OEMID, rxsdt->length, rxsdt ); @@ -222,9 +220,8 @@ static inline void IoSearchAcpiTables(void) if (!checksum) { for (ulong i=0; i < N_SDT_TYPES; i++) { if (!strncmp(table->signature, SDTChar[i], 4)) { - DebugLog("ACPI System Table %s (OEM %s) length %d [%p]\n", + DebugLog("ACPI System Table %s length %d [%p]\n", SDTChar[i], - table->OEMID, table->length, table ); @@ -248,9 +245,8 @@ static inline void IoSearchAcpiTables(void) checksum = DoChecksum(dsdt, (size_t)dsdt->length, 0, 0); if (!checksum) { if (!strncmp(dsdt->signature, SDTChar[SDT_DSDT], 4)) { - DebugLog("ACPI System Table %s (OEM %s) length %d [%p]\n", + DebugLog("ACPI System Table %s length %d [%p]\n", SDTChar[SDT_DSDT], - dsdt->OEMID, dsdt->length, dsdt ); diff --git a/kaleid/kernel/io/pci.c b/kaleid/kernel/io/pci.c index 6e05afd..7f5c66a 100644 --- a/kaleid/kernel/io/pci.c +++ b/kaleid/kernel/io/pci.c @@ -22,27 +22,27 @@ // along with OS/K. If not, see . // //----------------------------------------------------------------------------// - #include #include #include -void* pciConfigBaseAddress = NULL; +static void *pciConfigBaseAddress = NULL; +// -------------------------------------------------------------------------- // -static inline void* pciGetConfigAddr(uchar bus, uchar device, +static inline void* pciGetConfigAddr(uchar bus, uchar device, uchar function, ushort offset) { if(device > 32) { - KernLog("pciGetConfigAddr(): bad device ID\n"); + DebugLog("pciGetConfigAddr(): bad device ID\n"); return 0; } if(function > 8) { - KernLog("pciGetConfigAddr(): bad function ID\n"); + DebugLog("pciGetConfigAddr(): bad function ID\n"); return 0; } if(offset > 4096) { - KernLog("pciGetConfigAddr(): bad register offset\n"); + DebugLog("pciGetConfigAddr(): bad register offset\n"); return 0; } @@ -68,7 +68,6 @@ static inline uint pciReadConfigDWord(uchar bus, uchar device, return *((uint*)(pciGetConfigAddr(bus, device, function, offset))); } - //----------------------------------------------------------------------------// uchar IoPciReadConfigByte(PciDev_t *device, ushort offset) @@ -104,12 +103,10 @@ void IoPciWriteConfigDWord(PciDev_t *device, ushort offset, uint data) memmove((void *)((ulong)device->configAddr + offset), &data, 4); } - - void IoPciEnumerate() { if(pciConfigBaseAddress == NULL) { - KernLog("Unable to access PCI configuration : MCFG table not reachable\n"); + KeStartPanic("Unable to access PCI configuration : MCFG table not reachable\n"); return; } @@ -118,7 +115,7 @@ void IoPciEnumerate() for(uchar function = 0; function < 8; function++) { ushort vendor = pciReadConfigWord((uchar)bus, device, function, PCI_REG_VENDOR); if(vendor == 0xffff) continue; - DebugLog("PCI device found ! vendor: %x, device: %x\n", + DebugLog("PCI device vendor: %x, device: %x\n", vendor, pciReadConfigWord((uchar)bus, device, function, PCI_REG_DEVICE) ); @@ -130,7 +127,7 @@ void IoPciEnumerate() PciDev_t *IoPciGetDevice(ushort vendorID, ushort deviceID) { if(pciConfigBaseAddress == NULL) { - KernLog("Unable to access PCI configuration : MCFG table not reachable\n"); + KeStartPanic("Unable to access PCI configuration : MCFG table not reachable\n"); return NULL; } @@ -153,9 +150,9 @@ PciDev_t *IoPciGetDevice(ushort vendorID, ushort deviceID) void IoInitPCI() { - struct MCFG_t *MCFG_table = (struct MCFG_t*)IoGetAcpiTable(SDT_MCFG); + MCFG_t *MCFG_table = (MCFG_t*)IoGetAcpiTable(SDT_MCFG); if(MCFG_table == NULL) { - KernLog("Unable to access PCI configuration : MCFG table not reachable\n"); + KeStartPanic("Unable to access PCI configuration : MCFG table not reachable\n"); } pciConfigBaseAddress = MCFG_table->pciConfigBaseAddress; DebugLog("PCI Config Base address = 0x%p\n", pciConfigBaseAddress); @@ -165,11 +162,8 @@ void IoInitPCI() // Give R/W access to the configuration space for(int i=0; i < 65536; i++) // 65536 = 256 * 32 * 8 { - // 4096 for page size TODO: use of KPAGESIZE - MmMapPage((void *)((ulong)pciConfigBaseAddress + i * 4096), - (void *)((ulong)pciConfigBaseAddress + i * 4096), PRESENT | READWRITE); + MmMapPage((void *)((ulong)pciConfigBaseAddress + i * KPAGESIZE), + (void *)((ulong)pciConfigBaseAddress + i * KPAGESIZE), + PRESENT | READWRITE); } } - - -