Skip to content

Commit 6e6366a

Browse files
Added lspci print function, will we added to sh soon.
1 parent 002020f commit 6e6366a

4 files changed

Lines changed: 45 additions & 9 deletions

File tree

source/includes/graphics.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,7 @@ void done(cstring message, cstring file);
8989
*/
9090
void putc(char c);
9191

92-
/**
93-
* @brief Prints decimal numbers
94-
*
95-
* @param num the number to be printed
96-
*/
97-
void printdec(int num);
92+
9893

9994
/**
10095
* @brief Prints a value in binary format
@@ -172,7 +167,7 @@ int snprintf(char *buf, size_t size, const char *fmt, ...);
172167
* @param c char to print
173168
* @note Internally using Flanterm's putchar function
174169
*/
175-
void vputc(char c);
170+
void vputc(char c);
176171

177172
/**
178173
* @brief Print function for plain strings. (No Formatter)

source/includes/pci.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extern cstring display_adapter_name;
2525
extern cstring GPUName[1]; //Max 2 GPUs allowed
2626
extern string using_graphics_card;
2727
extern int64* graphics_base_Address;
28+
extern int total_devices;
2829

2930
// Define the base address for the PCI configuration space
3031
#define PCI_CONFIG_ADDRESS 0xCF8

source/kernel/C/pci.c

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <pci.h>
1212

1313
int gpu_index = 0;
14+
int total_devices = 0;
15+
1416
cstring display_adapter_name = "Frost Generic Display Adapter";
1517
cstring GPUName[1] = {"Frost Generic Display Driver for Graphics Processing Unit"}; // Max 2 GPUs allowed
1618

@@ -21,6 +23,12 @@ typedef void (*pci_probe_fn)(
2123
uint8_t bus, uint8_t slot, uint8_t function
2224
);
2325

26+
typedef struct {
27+
int16 bus;
28+
int16 slot;
29+
int16 func;
30+
} pci_location_t;
31+
2432
typedef struct {
2533
uint16_t vendor;
2634
uint16_t device;
@@ -204,6 +212,7 @@ void load_graphics_card(int16 bus, int16 slot, int16 function, cstring graphics_
204212
char* vendorNames[512];
205213
char* deviceNames[512];
206214
char* classNames[512];
215+
pci_location_t pciLocations[512];
207216

208217
/**
209218
* @brief Scans (Probes) PCI Devices
@@ -261,17 +270,20 @@ void probe_pci(){
261270
snprintf(deviceName, sizeof(deviceNameBuffer), "Unknown Device (0x%04X)", device);
262271
}
263272

273+
264274
print(green_color);
265275
printf("%9s : Device : %9s -- Class : %9s", vendorName, deviceName, className);
266276
print(reset_color);
267-
277+
268278
debug_printf(green_color);
269279
debug_printf("%s : Device : %s -- Class : %s\n", vendorName, deviceName, className);
270280
debug_printf(reset_color);
271-
281+
272282
vendorNames[i] = vendorName;
273283
deviceNames[i] = deviceName;
274284
classNames[i] = className;
285+
pciLocations[i] = (pci_location_t){bus, slot, function};
286+
275287
vendorName = "";
276288
deviceName = "";
277289
className = "";
@@ -282,7 +294,24 @@ void probe_pci(){
282294
done("Successfully completed probe!", __FILE__);
283295
done("Successfully saved to a array and verified.", __FILE__);
284296

297+
total_devices = i;
298+
printf("Total PCI Devices : %02d", total_devices);
285299
printf(yellow_color "GPU(0) : %s", GPUName[0]);
286300
printf("GPU(1) : %s" reset_color, GPUName[1]);
287301
printf("Display Adapter : %s", display_adapter_name);
302+
}
303+
304+
void print_lspci() {
305+
for (int i = 0; i < total_devices; i++) {
306+
if (vendorNames[i] == NULL || deviceNames[i] == NULL || classNames[i] == NULL)
307+
continue; // Skip empty entries
308+
309+
printf("%02d:%2x.%d " yellow_color "%s " green_color "%s " red_color "%s" reset_color,
310+
pciLocations[i].bus,
311+
pciLocations[i].slot,
312+
pciLocations[i].func,
313+
vendorNames[i],
314+
deviceNames[i],
315+
classNames[i]);
316+
}
288317
}

source/kernel/C/pci_id.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,22 @@
1414

1515
static pci_id_entry_t pci_ids[] = {
1616

17+
// * This is the entire array for the known PCI devices.
18+
// FORMAT :
19+
// {vendor, device, class, name, isgpu, handler_function}
20+
//
21+
// class may be 0xFF which means any class.
22+
1723
// --- Intel chipset ---
1824
{0x8086, 0x29C0, 0xFF, "(Intel) Express DRAM Controller", 0, NULL},
1925
{0x8086, 0x2918, 0xFF, "(Intel) LPC Interface Controller", 0, NULL},
2026
{0x8086, 0x2922, 0xFF, "(Intel) 6 port SATA Controller [AHCI mode]", 0, probe_ahci},
2127
{0x8086, 0x2930, 0xFF, "(Intel) SMBus Controller", 0, NULL},
28+
{0x8086, 0x1237, 0xFF, "440FX - 82441FX PMC [Natoma]", 0, NULL},
29+
{0x8086, 0x7000, 0xFF, "82371SB PIIX3 ISA [Natoma/Triton II]", 0, NULL},
30+
{0x8086, 0x7010, 0xFF, "82371SB PIIX3 IDE [Natoma/Triton II]", 0, NULL},
31+
{0x8086, 0x7113, 0xFF, "82371AB/EB/MB PIIX4 ACPI", 0, NULL},
32+
2233

2334
// --- AMD chipset ---
2435
{0x1022, 0x7800, 0xFF, "AMD SATA Controller [AHCI]", 0, probe_ahci},

0 commit comments

Comments
 (0)