Compare commits
3 Commits
BasicGraph
...
08b97af863
Author | SHA1 | Date | |
---|---|---|---|
08b97af863 | |||
5089da5e9e | |||
ec654143c6 |
24
Makefile
24
Makefile
@ -5,7 +5,21 @@ CC = ${HOME}/opt/cross/bin/i686-elf-gcc
|
|||||||
CPP = ${HOME}/opt/cross/bin/i686-elf-g++
|
CPP = ${HOME}/opt/cross/bin/i686-elf-g++
|
||||||
CFLAGS = -ffreestanding -O2 -Wall -Wextra
|
CFLAGS = -ffreestanding -O2 -Wall -Wextra
|
||||||
|
|
||||||
OFILES = $(BUILD_DIR)/boot.o $(BUILD_DIR)/kterm.o $(BUILD_DIR)/kernel.o $(BUILD_DIR)/PhysicalMemoryManager.o $(BUILD_DIR)/io.o $(BUILD_DIR)/PageDirectory.o $(BUILD_DIR)/gdtc.o $(BUILD_DIR)/idt.o $(BUILD_DIR)/pic.o $(BUILD_DIR)/string.o
|
OFILES = \
|
||||||
|
$(BUILD_DIR)/boot.o \
|
||||||
|
$(BUILD_DIR)/kterm.o \
|
||||||
|
$(BUILD_DIR)/kernel.o \
|
||||||
|
$(BUILD_DIR)/PhysicalMemoryManager.o \
|
||||||
|
$(BUILD_DIR)/io.o \
|
||||||
|
$(BUILD_DIR)/PageDirectory.o \
|
||||||
|
$(BUILD_DIR)/gdtc.o \
|
||||||
|
$(BUILD_DIR)/idt.o \
|
||||||
|
$(BUILD_DIR)/pci.o \
|
||||||
|
$(BUILD_DIR)/pic.o \
|
||||||
|
$(BUILD_DIR)/string.o \
|
||||||
|
$(BUILD_DIR)/pcidevice.o
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
SRC_DIR = src
|
SRC_DIR = src
|
||||||
BUILD_DIR = build
|
BUILD_DIR = build
|
||||||
@ -36,7 +50,7 @@ iso: clean_iso clean build
|
|||||||
grub-mkrescue -o build/barinkOS.iso root
|
grub-mkrescue -o build/barinkOS.iso root
|
||||||
|
|
||||||
test:
|
test:
|
||||||
$(EMULATOR) -kernel $(BUILD_DIR)/myos.bin -serial stdio -vga std -monitor stdio -display gtk -m 2G -cpu core2duo
|
$(EMULATOR) -kernel $(BUILD_DIR)/myos.bin -serial stdio -vga std -display gtk -m 2G -cpu core2duo
|
||||||
|
|
||||||
build_kernel: $(OBJ_LINK_LIST)
|
build_kernel: $(OBJ_LINK_LIST)
|
||||||
$(CC) -T $(SRC_DIR)/kernel//linker.ld -o $(BUILD_DIR)/myos.bin \
|
$(CC) -T $(SRC_DIR)/kernel//linker.ld -o $(BUILD_DIR)/myos.bin \
|
||||||
@ -85,3 +99,9 @@ $(BUILD_DIR)/string.o:
|
|||||||
|
|
||||||
$(BUILD_DIR)/PhysicalMemoryManager.o:
|
$(BUILD_DIR)/PhysicalMemoryManager.o:
|
||||||
$(CPP) -c $(SRC_DIR)/kernel/memory/PhysicalMemoryManager.cpp -o $(BUILD_DIR)/PhysicalMemoryManager.o $(CFLAGS) -fno-exceptions -fno-rtti
|
$(CPP) -c $(SRC_DIR)/kernel/memory/PhysicalMemoryManager.cpp -o $(BUILD_DIR)/PhysicalMemoryManager.o $(CFLAGS) -fno-exceptions -fno-rtti
|
||||||
|
|
||||||
|
$(BUILD_DIR)/pci.o:
|
||||||
|
$(CPP) -c $(SRC_DIR)/kernel/pci.cpp -o $(BUILD_DIR)/pci.o $(CFLAGS) -fno-exceptions -fno-rtti
|
||||||
|
|
||||||
|
$(BUILD_DIR)/pcidevice.o:
|
||||||
|
$(CPP) -c $(SRC_DIR)/kernel/pci/pciDevice.cpp -o $(BUILD_DIR)/pcidevice.o $(CFLAGS) -fno-exceptions -fno-rtti
|
||||||
|
@ -52,10 +52,6 @@ void initGDT(){
|
|||||||
|
|
||||||
LoadGlobalDescriptorTable();
|
LoadGlobalDescriptorTable();
|
||||||
|
|
||||||
while (true)
|
|
||||||
asm volatile("hlt");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,10 @@ unsigned short inw_p(unsigned short ){
|
|||||||
// TODO: implement me!
|
// TODO: implement me!
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
unsigned int inl(unsigned short ){
|
uint32_t inl( int port ){
|
||||||
// TODO: implement me!
|
unsigned int data;
|
||||||
return 0;
|
asm volatile ("inl %w1, %0": "=a" (data): "d" (port));
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
unsigned int inl_p(unsigned short ){
|
unsigned int inl_p(unsigned short ){
|
||||||
// TODO: implement me!
|
// TODO: implement me!
|
||||||
@ -31,9 +32,12 @@ void outw(unsigned short , unsigned short ){
|
|||||||
void outw_p(unsigned short , unsigned short ){
|
void outw_p(unsigned short , unsigned short ){
|
||||||
|
|
||||||
}
|
}
|
||||||
void outl(unsigned int , unsigned short ){
|
|
||||||
|
|
||||||
|
void outl( int port , uint32_t data ){
|
||||||
|
asm volatile ("outl %0, %1" :: "a" (data), "dn"(port));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void outl_p(unsigned int , unsigned short ){
|
void outl_p(unsigned int , unsigned short ){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,21 +12,17 @@ static inline uint8_t inb(uint16_t port)
|
|||||||
unsigned char inb_p(unsigned short port);
|
unsigned char inb_p(unsigned short port);
|
||||||
unsigned short inw(unsigned short port);
|
unsigned short inw(unsigned short port);
|
||||||
unsigned short inw_p(unsigned short port);
|
unsigned short inw_p(unsigned short port);
|
||||||
unsigned int inl(unsigned short port);
|
uint32_t inl( int port );
|
||||||
unsigned int inl_p(unsigned short port);
|
unsigned int inl_p(unsigned short port);
|
||||||
|
|
||||||
static inline void outb(uint16_t port, uint8_t val)
|
static inline void outb(uint16_t port, uint8_t val)
|
||||||
{
|
{
|
||||||
asm volatile ( "outb %0, %1" : : "a"(val), "Nd"(port) );
|
asm volatile ( "outb %0, %1" : : "a"(val), "Nd"(port) );
|
||||||
/* There's an outb %al, $imm8 encoding, for compile-time constant port numbers that fit in 8b. (N constraint).
|
|
||||||
* Wider immediate constants would be truncated at assemble-time (e.g. "i" constraint).
|
|
||||||
* The outb %al, %dx encoding is the only option for all other cases.
|
|
||||||
* %1 expands to %dx because port is a uint16_t. %w1 could be used if we had the port number a wider C type */
|
|
||||||
}
|
}
|
||||||
void outb_p(unsigned char value, unsigned short port);
|
void outb_p(unsigned char value, unsigned short port);
|
||||||
void outw(unsigned short value, unsigned short port);
|
void outw(unsigned short value, unsigned short port);
|
||||||
void outw_p(unsigned short value, unsigned short port);
|
void outw_p(unsigned short value, unsigned short port);
|
||||||
void outl(unsigned int value, unsigned short port);
|
void outl( int port , uint32_t data );
|
||||||
void outl_p(unsigned int value, unsigned short port);
|
void outl_p(unsigned int value, unsigned short port);
|
||||||
|
|
||||||
void insb(unsigned short port, void *addr,
|
void insb(unsigned short port, void *addr,
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
#define GB4 524288
|
#define GB4 524288
|
||||||
#define GB2 262144
|
#define GB2 262144
|
||||||
|
|
||||||
|
int memcmp( const void* ptr1, const void* ptr2, size_t num);
|
||||||
|
|
||||||
|
extern "C" void kernel_main (void);
|
||||||
|
|
||||||
extern "C" void early_main(unsigned long magic, unsigned long addr){
|
extern "C" void early_main(unsigned long magic, unsigned long addr){
|
||||||
/** initialize terminal interface */
|
/** initialize terminal interface */
|
||||||
kterm_init();
|
kterm_init();
|
||||||
@ -29,12 +34,39 @@
|
|||||||
initGDT();
|
initGDT();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
kernel_main();
|
||||||
|
}
|
||||||
|
|
||||||
|
int memcmp( const void* ptr1, const void* ptr2, size_t num)
|
||||||
|
{
|
||||||
|
const unsigned char * cs = (const unsigned char*) ptr1;
|
||||||
|
const unsigned char * ct = (const unsigned char*) ptr2;
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 0 ; i < num ; i++, cs++, ct++ ){
|
||||||
|
if( *cs < *ct){
|
||||||
|
return -1;
|
||||||
|
} else if( *cs > *ct){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void kernel_main (void) {
|
extern "C" void kernel_main (void) {
|
||||||
|
|
||||||
printf("call to init serial\n");
|
printf("call to init serial\n");
|
||||||
init_serial();
|
init_serial();
|
||||||
|
print_serial("Serial port initialized!");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Enumerate the PCI bus
|
||||||
|
PCI_Enumerate();
|
||||||
|
|
||||||
|
|
||||||
while (true){
|
while (true){
|
||||||
//Read time indefinetely
|
//Read time indefinetely
|
||||||
|
@ -16,6 +16,9 @@ extern "C"{
|
|||||||
#include "time.h"
|
#include "time.h"
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "serial.h"
|
#include "serial.h"
|
||||||
|
#include "pci.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define CHECK_FLAG(flags, bit) ((flags) & (1 <<(bit)))
|
#define CHECK_FLAG(flags, bit) ((flags) & (1 <<(bit)))
|
||||||
#define PANIC(message) { return; }
|
#define PANIC(message) { return; }
|
||||||
|
@ -1,108 +1,246 @@
|
|||||||
#include "pci.h"
|
#include "pci.h"
|
||||||
|
|
||||||
uint16_t ConfigReadWord (uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset){
|
#define PCI_BUS_ADDR_SHIFT 16
|
||||||
uint32_t address;
|
#define PCI_DEVICE_ADDR_SHIFT 11
|
||||||
uint32_t lbus = (uint32_t) bus;
|
#define PCI_FUNCTION_ADDR_SHIFT 8
|
||||||
uint32_t lslot = (uint32_t) slot;
|
#define PCI_ENABLE_ADDR_SHIFT 31
|
||||||
uint32_t lfunc = (uint32_t) func;
|
|
||||||
uint16_t tmp = 0;
|
|
||||||
|
|
||||||
/* Create configuration address as per Figure 1 */
|
const char* GetClassCodeName (uint64_t ClassCode ) {
|
||||||
address = (uint32_t) ((lbus << 16) | (lslot << 11) | (lfunc << 8) | (offset & 0xFC) |((uint32_t) 0x80000000) );
|
|
||||||
/*write out the address */
|
|
||||||
outl(CONFIG_ADDRESS, address);
|
|
||||||
/* read in the data */
|
|
||||||
/* (offset & 2 ) * 8 ) = o will choosse the first word of the 32 bits register*/
|
|
||||||
tmp = (uint16_t)((inl(CONFIG_DATA)) >> ((offset & 2) * 8) & 0xFFFF);
|
|
||||||
return (tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t CheckVendor (uint8_t bus, uint8_t slot) {
|
switch (ClassCode)
|
||||||
uint16_t vendor, device;
|
{
|
||||||
/*
|
case 0x0 :
|
||||||
Try and read the first configuration register. Since there ar no
|
return "Unclassified";
|
||||||
vendors that == 0xFFFF, it must be a non-existent device.
|
break;
|
||||||
*/
|
|
||||||
if((vendor = ConfigReadWord(bus, slot, 0,0)) != 0xFFFF) {
|
|
||||||
device = ConfigReadWord(bus, slot, 0,2);
|
|
||||||
// Possible read more config values ...
|
|
||||||
} return (vendor);
|
|
||||||
}
|
|
||||||
|
|
||||||
void checkDevice (uint8_t bus, uint8_t device ) {
|
case 0x1:
|
||||||
uint8_t function = 0;
|
return "Mass Storage Controller";
|
||||||
|
break;
|
||||||
|
|
||||||
uint16_t vendorID = CheckVendor(bus, device);
|
case 0x2:
|
||||||
if (vendorID == 0xFFFF) {
|
return "Network Controller";
|
||||||
return;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
checkFunction (bus, device, function );
|
case 0x3:
|
||||||
headerType = getHeaderType(bus, device, function );
|
return "Display Controller";
|
||||||
if( (headerType & 0x80) != 0) {
|
break;
|
||||||
/* It is a multi-function device, so check remaining functions */
|
|
||||||
for (function = 1; function < 8; function++){
|
|
||||||
if (CheckVendor(bus, device)!= 0xFFFF){
|
|
||||||
checkFunction(bus, device, function );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
case 0x4:
|
||||||
|
return "Multimedia Controller";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0x5:
|
||||||
|
return "Memory Controller";
|
||||||
|
break;
|
||||||
|
|
||||||
void checkFunction (uint8_t bus, uint8_t device, uint8_t function ){
|
case 0x6:
|
||||||
uint8_t baseClass;
|
return "Bridge";
|
||||||
uint8_t subClass;
|
break;
|
||||||
uint8_t secondaryBus;
|
|
||||||
|
|
||||||
baseClass = getBaseClass(bus, device, function);
|
case 0x7 :
|
||||||
subClass = getSubClass (bus, device, function );
|
return "Simple Communication Controller";
|
||||||
if ( (baseClass == 0x06) && (subClass == 0x04)){
|
break;
|
||||||
secondaryBus = getSecondaryBus(bus,device, function);
|
|
||||||
checkBus(secondaryBus);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
case 0x8:
|
||||||
|
return "Base System Peripheral";
|
||||||
|
break;
|
||||||
|
|
||||||
// Brute-force scan
|
case 0x9:
|
||||||
void checkAllBuses (){
|
return "Input Device Controller";
|
||||||
uint16_t bus;
|
break;
|
||||||
uint8_t device;
|
|
||||||
|
|
||||||
for(bus = 0; bus < 256; bus++){
|
case 0xA:
|
||||||
for(device = 0; device < 32; device++){
|
return "Docking station";
|
||||||
checkDevice(bus,device);
|
break;
|
||||||
}
|
case 0xB:
|
||||||
}
|
return "Processor";
|
||||||
}
|
break;
|
||||||
|
|
||||||
// Recursive scan
|
case 0xC:
|
||||||
void checkBus (uint8_t bus){
|
return "Serial Bus Controller";
|
||||||
uint8_t device;
|
break;
|
||||||
|
|
||||||
for(device = 0; device < 32; device ++){
|
case 0xD:
|
||||||
checkDevice(bus,device);
|
return "Wireless Controller";
|
||||||
}
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
void checkAllBuses(){
|
case 0xE:
|
||||||
uint8_t function;
|
return "Intelligent Controller";
|
||||||
uint8_t bus;
|
break;
|
||||||
|
|
||||||
headerType = getHeaderType(0,0,0);
|
case 0xF:
|
||||||
if ( (headerType & 0x80) == 0 ){
|
return "Satellite Communication Controller";
|
||||||
/* Single PCI host controller */
|
break;
|
||||||
checkBus(0);
|
|
||||||
} else{
|
case 0x10:
|
||||||
/* Multiple PCI host controllers */
|
return "Encryption Controller";
|
||||||
for (function = 0; function < 8; function++){
|
break;
|
||||||
if( CheckVendor(0,0) != 0xFFFF) {
|
|
||||||
|
case 0x11:
|
||||||
|
return "Signal Processing Controller";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0x12:
|
||||||
|
return "Processing Accelerator";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0x13:
|
||||||
|
return "Non-Essential Instrumentation";
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return "Unknown";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
bus = function;
|
|
||||||
checkBus(bus);
|
}
|
||||||
}
|
|
||||||
|
const char* getVendor( uint32_t VendorID){
|
||||||
|
switch (VendorID)
|
||||||
|
{
|
||||||
|
case 0x8086:
|
||||||
|
return "Intel Corporation";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0x10DE:
|
||||||
|
return "NVIDIA Corporation";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0x1022:
|
||||||
|
return "Advanced Micro Devices, Inc.[AMD]";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 0x1002:
|
||||||
|
return "Advanced Micor Devices, Inc.[AMD/ATI]";
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return "Vendor Unkown";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t ConfigReadWord ( PCIBusAddress& PCIDeviceAddress , uint8_t offset){
|
||||||
|
outl(CONFIG_ADDRESS , PCIDeviceAddress.getAddress() | offset );
|
||||||
|
return inl(CONFIG_DATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t ConfigReadWord (uint8_t bus, uint8_t device, uint8_t func, uint8_t offset){
|
||||||
|
uint32_t address;
|
||||||
|
|
||||||
|
address = (uint32_t) (
|
||||||
|
((uint32_t) 1 << PCI_ENABLE_ADDR_SHIFT) |
|
||||||
|
((uint32_t)bus << PCI_BUS_ADDR_SHIFT) |
|
||||||
|
((uint32_t)device << PCI_DEVICE_ADDR_SHIFT) |
|
||||||
|
((uint32_t)func << PCI_FUNCTION_ADDR_SHIFT) |
|
||||||
|
offset );
|
||||||
|
|
||||||
|
outl(CONFIG_ADDRESS, address);
|
||||||
|
|
||||||
|
|
||||||
|
return inl(CONFIG_DATA);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t GetHeaderType( PCIBusAddress& PCIDeviceAddress ){
|
||||||
|
uint32_t header_information = ConfigReadWord(PCIDeviceAddress , 0xC);
|
||||||
|
return (uint8_t) (
|
||||||
|
((header_information >> 16) //Get higher half
|
||||||
|
& 0x00FF) // Select the last two bytes
|
||||||
|
& 0x7F ); // Mask bit 7 as it indicates if the device is a mulit function device!
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t GetClassCodes( PCIBusAddress& PCIDeviceAddress ){
|
||||||
|
uint32_t classcodes = ConfigReadWord(PCIDeviceAddress, 0x8);
|
||||||
|
return (uint16_t)((uint32_t)classcodes >> 16);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool IsMultiFunctionDevice(PCIBusAddress& PCIDeviceAddress){
|
||||||
|
uint32_t header_information = ConfigReadWord(PCIDeviceAddress, 0xC);
|
||||||
|
return (((header_information>>16)
|
||||||
|
& 0x80)
|
||||||
|
>> 7 );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void PrintPCIDeviceInfo (PCIBusAddress& PCIDeviceAddress)
|
||||||
|
{
|
||||||
|
uint32_t DeviceID = (GetDevice(PCIDeviceAddress.bus, PCIDeviceAddress.device, PCIDeviceAddress.function) >> 16);
|
||||||
|
uint32_t VendorID = GetDevice(PCIDeviceAddress.bus, PCIDeviceAddress.device, PCIDeviceAddress.function) & 0xFFFF;
|
||||||
|
printf("Device found!\n");
|
||||||
|
printf("Bus: %d, Device: %d, function: %d \n", PCIDeviceAddress.bus, PCIDeviceAddress.device, PCIDeviceAddress.function);
|
||||||
|
printf("DeviceID: 0x%x, Vendor: %s\n",
|
||||||
|
DeviceID
|
||||||
|
, getVendor(VendorID) );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
uint8_t header_type = GetHeaderType(PCIDeviceAddress);
|
||||||
|
printf( "Header type: 0x%x\n", header_type);
|
||||||
|
|
||||||
|
uint16_t deviceClasses = GetClassCodes(PCIDeviceAddress);
|
||||||
|
printf("class: %s, subClass: %d\n\n", GetClassCodeName((deviceClasses >>8)), deviceClasses & 0xFF);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void PCI_Enumerate(){
|
||||||
|
int devicesFound = 0;
|
||||||
|
// loop through all possible busses, devices and their functions;
|
||||||
|
for( int bus = 0 ; bus < 256 ; bus++)
|
||||||
|
{
|
||||||
|
|
||||||
|
for(int device = 0; device < 32 ; device ++)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
int function = 0;
|
||||||
|
|
||||||
|
//uint64_t DeviceIdentify = ConfigReadWord(bus, device, function,0x0);
|
||||||
|
uint32_t DeviceID = GetDevice(bus, device, function) >> 16;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if( DeviceID != 0xFFFF){
|
||||||
|
PCIBusAddress busAddress =
|
||||||
|
PCIBusAddress{bus, device, function };
|
||||||
|
|
||||||
|
PrintPCIDeviceInfo(busAddress);
|
||||||
|
|
||||||
|
// iterate over the functions if it is a multi function device!
|
||||||
|
if( IsMultiFunctionDevice(busAddress) ){
|
||||||
|
printf("Multi function device! \n");
|
||||||
|
printf("Check remaining Functions\n");
|
||||||
|
for ( function = 1 ; function < 8; function++)
|
||||||
|
{
|
||||||
|
uint32_t DeviceID = GetDevice(bus, device, function) >> 16;
|
||||||
|
|
||||||
|
if( DeviceID != 0xFFFF){
|
||||||
|
PCIBusAddress busAddress2 = PCIBusAddress{bus, device, function};
|
||||||
|
PrintPCIDeviceInfo(busAddress2);
|
||||||
|
devicesFound++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
devicesFound++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Found %d PCI devices!\n", devicesFound);
|
||||||
|
}
|
||||||
|
@ -1,58 +1,35 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
|
#include "tty/kterm.h"
|
||||||
|
#include "pci/pciDevice.h"
|
||||||
|
|
||||||
// Configuration Space Access Mechanism #1
|
// Configuration Space Access Mechanism #1
|
||||||
#define CONFIG_ADDRESS 0xCF8 // Configuration adress that is to be accessed
|
#define CONFIG_ADDRESS 0xCF8 // Configuration adress that is to be accessed
|
||||||
#define CONFIG_DATA 0xCFC // Will do the actual configuration operation
|
#define CONFIG_DATA 0xCFC // Will do the actual configuration operation
|
||||||
|
|
||||||
/*
|
extern const char* ClassCodeTable [0x13];
|
||||||
CONFIG_ADDRESS
|
|
||||||
|
|
||||||
32 bit register
|
|
||||||
|
|
||||||
bit 31 Enable bit (Should CONFIG_DATA be translatedc to configuration cycles)
|
|
||||||
bit 30 - 24 Reserved
|
|
||||||
bit 23 - 16 Bus Number (Choose a specific PCI BUS)
|
|
||||||
bit 15 - 11 Device Number (Selects specific device one the pci bus)
|
|
||||||
bit 10 - 8 Function Number (Selects a specific function in a device)
|
|
||||||
bit 7 - 0 Register Offset (Offset in the configuration space of 256 Bytes ) NOTE: lowest two bits will always be zero
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
PCI Device structure
|
|
||||||
|
|
||||||
Register offset bits 31-24 bits 23-16 bits 15-8 bits 7-0
|
// Note: this could be used to make the api for receiving PCI class codes a bit
|
||||||
00 00 Device ID <---- Vendor ID <-------
|
// nicer.
|
||||||
01 04 Status <---- Command <-------
|
struct ClassCodes {
|
||||||
02 08 Class code Sub class Prog IF Revision ID
|
uint8_t ClassCode;
|
||||||
03 0C BIST Header Type Ltncy Timer Cache line Size
|
uint8_t DeviceClass;
|
||||||
04 10 Base address #0 (BAR0)
|
}__attribute__((packed));
|
||||||
05 14 Base address #1 (BAR1)
|
|
||||||
06 18 Base address #2 (BAR2)
|
|
||||||
07 1C Base address #3 (BAR3)
|
|
||||||
08 20 Base address #4 (BAR4)
|
|
||||||
09 24 Base address #5 (BAR5)
|
|
||||||
0A 28 Cardbus CIS Pointer
|
|
||||||
0B 2C Subsystem ID <------ Subsystem Vendor ID <-------
|
|
||||||
0C 30 Expansion ROM base address
|
|
||||||
0D 34 Reserved <------- Capabilities Pointer <------
|
|
||||||
0E 38 Reserved <------- <-------- <--------
|
|
||||||
0F 3C Max ltncy Min Grant Interrupt PIN Interrupt Line
|
|
||||||
|
|
||||||
*/
|
uint32_t ConfigReadWord (uint8_t bus, uint8_t device, uint8_t func, uint8_t offset);
|
||||||
|
uint32_t ConfigReadWord ( PCIBusAddress& PCIDeviceAddress , uint8_t offset);
|
||||||
|
|
||||||
|
inline uint64_t GetDevice (int bus, int device, int function ){
|
||||||
|
return ConfigReadWord(bus, device, function,0x0);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
uint8_t GetHeaderType( PCIBusAddress& PCIDeviceAddress );
|
||||||
The idea for now is to support the minimal things necessary to find ATA supported drives
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
uint16_t GetClassCodes( PCIBusAddress& PICDeviceAddress );
|
||||||
|
const char* getVendor( uint64_t VendorID);
|
||||||
|
const char* GetClassCodeName (uint64_t ClassCode );
|
||||||
|
|
||||||
// Lets write some boiler plate configuration code
|
void PCI_Enumerate();
|
||||||
|
|
||||||
uint16_t ConfigReadWord (uint8_t bus, uint8_t slot, uint8_t func, uint8_t offset);
|
|
||||||
|
|
||||||
uint16_t CheckVendor (uint8_t bus, uint8_t slot);
|
|
||||||
|
|
||||||
void checkDevice (uint8_t bus, uint8_t device );
|
|
7
src/kernel/pci/pciDevice.cpp
Normal file
7
src/kernel/pci/pciDevice.cpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#include "pciDevice.h"
|
||||||
|
|
||||||
|
// NOTE: we would really like to return a pointer
|
||||||
|
// to the newly created PCIBusAddress struct;
|
||||||
|
PCIBusAddress const PCIDevice::PCIAddress(){
|
||||||
|
return PCIBusAddress{bus ,device, function};
|
||||||
|
}
|
54
src/kernel/pci/pciDevice.h
Normal file
54
src/kernel/pci/pciDevice.h
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <stdint.h>
|
||||||
|
/*
|
||||||
|
* PCI devices API
|
||||||
|
*/
|
||||||
|
struct PCIBusAddress{
|
||||||
|
|
||||||
|
int bus ;
|
||||||
|
int device ;
|
||||||
|
int function;
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t getAddress( ){
|
||||||
|
return ((uint32_t) 1 << 31) |
|
||||||
|
((uint32_t) bus << 16) |
|
||||||
|
((uint32_t) device << 11)|
|
||||||
|
((uint32_t) function << 8) |
|
||||||
|
0x0000;
|
||||||
|
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
class PCIDevice {
|
||||||
|
public :
|
||||||
|
PCIDevice (PCIBusAddress* , int );
|
||||||
|
~PCIDevice();
|
||||||
|
PCIBusAddress const PCIAddress();
|
||||||
|
|
||||||
|
|
||||||
|
inline const char* getDeviceString(){
|
||||||
|
return "Not implemented"; //GetClassCodeName(deviceclass);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const char* getVendorString(){
|
||||||
|
return "Not implemented"; // getVendor(VendorID);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void setVendorID (uint16_t id) {
|
||||||
|
this->VendorID = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
int bus;
|
||||||
|
int device;
|
||||||
|
int function;
|
||||||
|
|
||||||
|
uint16_t VendorID;
|
||||||
|
uint16_t DeviceID;
|
||||||
|
uint8_t deviceclass;
|
||||||
|
uint8_t devicesubclass;
|
||||||
|
|
||||||
|
int headerType;
|
||||||
|
|
||||||
|
};
|
Reference in New Issue
Block a user