2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2020-03-06 11:59:29 -03:00
|
|
|
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2020-04-09 13:17:27 -03:00
|
|
|
#include <Kernel/ACPI/Parser.h>
|
2021-06-25 03:46:17 -03:00
|
|
|
#include <Kernel/Bus/PCI/IOAccess.h>
|
|
|
|
|
#include <Kernel/Bus/PCI/Initializer.h>
|
|
|
|
|
#include <Kernel/Bus/PCI/MMIOAccess.h>
|
|
|
|
|
#include <Kernel/Bus/PCI/WindowedMMIOAccess.h>
|
2020-04-08 08:54:44 -03:00
|
|
|
#include <Kernel/CommandLine.h>
|
2020-09-18 04:49:51 -03:00
|
|
|
#include <Kernel/IO.h>
|
2021-02-14 05:30:31 -03:00
|
|
|
#include <Kernel/Panic.h>
|
2021-06-22 12:40:16 -03:00
|
|
|
#include <Kernel/Sections.h>
|
2019-12-31 08:04:30 -03:00
|
|
|
|
2020-02-15 21:27:42 -03:00
|
|
|
namespace Kernel {
|
2020-04-08 12:29:37 -03:00
|
|
|
namespace PCI {
|
2020-02-15 21:27:42 -03:00
|
|
|
|
2020-04-08 12:39:17 -03:00
|
|
|
static bool test_pci_io();
|
2020-04-08 13:06:08 -03:00
|
|
|
|
2021-04-03 10:46:04 -03:00
|
|
|
UNMAP_AFTER_INIT static PCIAccessLevel detect_optimal_access_type(PCIAccessLevel boot_determined)
|
2020-04-08 13:06:08 -03:00
|
|
|
{
|
2021-04-03 10:46:04 -03:00
|
|
|
if (!ACPI::is_enabled() || ACPI::Parser::the()->find_table("MCFG").is_null())
|
|
|
|
|
return PCIAccessLevel::IOAddressing;
|
|
|
|
|
|
|
|
|
|
if (boot_determined != PCIAccessLevel::IOAddressing)
|
|
|
|
|
return boot_determined;
|
2020-04-08 13:06:08 -03:00
|
|
|
|
|
|
|
|
if (test_pci_io())
|
2021-04-03 10:46:04 -03:00
|
|
|
return PCIAccessLevel::IOAddressing;
|
2020-04-08 13:06:08 -03:00
|
|
|
|
2021-02-14 05:30:31 -03:00
|
|
|
PANIC("No PCI bus access method detected!");
|
2020-04-08 13:06:08 -03:00
|
|
|
}
|
2019-12-31 08:04:30 -03:00
|
|
|
|
2021-02-19 17:29:46 -03:00
|
|
|
UNMAP_AFTER_INIT void initialize()
|
2019-12-31 08:04:30 -03:00
|
|
|
{
|
2021-04-03 10:46:04 -03:00
|
|
|
auto boot_determined = kernel_command_line().pci_access_level();
|
2020-04-08 13:06:08 -03:00
|
|
|
|
2021-04-03 10:46:04 -03:00
|
|
|
switch (detect_optimal_access_type(boot_determined)) {
|
|
|
|
|
case PCIAccessLevel::MappingPerDevice:
|
|
|
|
|
WindowedMMIOAccess::initialize(ACPI::Parser::the()->find_table("MCFG"));
|
|
|
|
|
break;
|
|
|
|
|
case PCIAccessLevel::MappingPerBus:
|
2020-04-09 09:31:47 -03:00
|
|
|
MMIOAccess::initialize(ACPI::Parser::the()->find_table("MCFG"));
|
2021-04-03 10:46:04 -03:00
|
|
|
break;
|
|
|
|
|
case PCIAccessLevel::IOAddressing:
|
2020-04-09 08:42:17 -03:00
|
|
|
IOAccess::initialize();
|
2021-04-03 10:46:04 -03:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
VERIFY_NOT_REACHED();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-10 20:31:48 -03:00
|
|
|
PCI::PCIBusSysFSDirectory::initialize();
|
2021-05-27 16:03:26 -03:00
|
|
|
|
2020-04-10 14:33:30 -03:00
|
|
|
PCI::enumerate([&](const Address& address, ID id) {
|
2021-03-12 09:57:56 -03:00
|
|
|
dmesgln("{} {}", address, id);
|
2020-02-01 20:52:51 -03:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-19 17:29:46 -03:00
|
|
|
UNMAP_AFTER_INIT bool test_pci_io()
|
2019-12-31 08:04:30 -03:00
|
|
|
{
|
2021-03-12 09:57:56 -03:00
|
|
|
dmesgln("Testing PCI via manual probing...");
|
2019-12-31 08:04:30 -03:00
|
|
|
u32 tmp = 0x80000000;
|
|
|
|
|
IO::out32(PCI_ADDRESS_PORT, tmp);
|
|
|
|
|
tmp = IO::in32(PCI_ADDRESS_PORT);
|
|
|
|
|
if (tmp == 0x80000000) {
|
2021-03-12 09:57:56 -03:00
|
|
|
dmesgln("PCI IO supported");
|
2019-12-31 08:04:30 -03:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 09:57:56 -03:00
|
|
|
dmesgln("PCI IO not supported");
|
2019-12-31 08:04:30 -03:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-15 21:27:42 -03:00
|
|
|
}
|
2020-04-08 12:29:37 -03:00
|
|
|
}
|