mirror of
https://gitlab.os-k.eu/os-k-team/os-k.git
synced 2023-08-25 14:03:10 +02:00
Update with pci
This commit is contained in:
commit
b21c07a8e2
@ -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));
|
||||
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
|
@ -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;
|
||||
|
@ -35,10 +35,14 @@
|
||||
#include <io/keyb.h>
|
||||
#include <io/cursor.h>
|
||||
#include <io/acpi.h>
|
||||
#include <io/pci.h>
|
||||
#include <po/shtdwn.h>
|
||||
#include <init/boot.h>
|
||||
<<<<<<< HEAD
|
||||
#include <io/pci.h>
|
||||
#include <drivers/rtl8139.h>
|
||||
=======
|
||||
>>>>>>> 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
|
||||
|
@ -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
|
||||
);
|
||||
|
@ -22,27 +22,27 @@
|
||||
// along with OS/K. If not, see <https://www.gnu.org/licenses/>. //
|
||||
//----------------------------------------------------------------------------//
|
||||
|
||||
|
||||
#include <io/pci.h>
|
||||
#include <io/acpi.h>
|
||||
#include <mm/paging.h>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user