/* Copyright (C) 2021 Rain */ /* This file is part of XNIX. */ /* XNIX is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) and later version. */ /* XNIX is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ /* You should have received a copy of the GNU General Public License along with XNIX. If not, see . */ #include #include #include #include #include #include #include __uint32_t pci_read_config(__uint8_t bus, __uint8_t slot, __uint8_t func, __uint8_t offset) { __uint32_t addr; #define lbus ((__uint32_t) bus) #define lslot ((__uint32_t) slot) #define lfunc ((__uint32_t) func) addr = (lbus << 16) | (lslot << 11) | (lfunc << 8) | (offset & 0xfc) | 0x80000000ul; outl(addr, 0xcf8); return inl(0xcfc); } __uint32_t pci_lspci(void) { __uint8_t bus, slot, func; __uint32_t devs = 0; for (bus = 0; bus < 255; bus++) { for (slot = 0; slot < 32; slot++) { for (func = 0; func < 8; func++) { if (pci_read_config(bus, slot, func, 0) != 0xffffffff) { /* exists */ printk(yellow, "pci: %b:%b:%b exists: %x. \n", bus, slot, func, pci_read_config(bus, slot, func, 0)); devs++; } } } } return devs; }