mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
25ea7461a0
A couple of things were changed: 1. Semantic changes - PCI segments are now called PCI domains, to better match what they are really. It's also the name that Linux gave, and it seems that Wikipedia also uses this name. We also remove PCI::ChangeableAddress, because it was used in the past but now it's no longer being used. 2. There are no WindowedMMIOAccess or MMIOAccess classes anymore, as they made a bunch of unnecessary complexity. Instead, Windowed access is removed entirely (this was tested, but never was benchmarked), so we are left with IO access and memory access options. The memory access option is essentially mapping the PCI bus (from the chosen PCI domain), to virtual memory as-is. This means that unless needed, at any time, there is only one PCI bus being mapped, and this is changed if access to another PCI bus in the same PCI domain is needed. For now, we don't support mapping of different PCI buses from different PCI domains at the same time, because basically it's still a non-issue for most machines out there. 2. OOM-safety is increased, especially when constructing the Access object. It means that we pre-allocating any needed resources, and we try to find PCI domains (if requested to initialize memory access) after we attempt to construct the Access object, so it's possible to fail at this point "gracefully". 3. All PCI API functions are now separated into a different header file, which means only "clients" of the PCI subsystem API will need to include that header file. 4. Functional changes - we only allow now to enumerate the bus after a hardware scan. This means that the old method "enumerate_hardware" is removed, so, when initializing an Access object, the initializing function must call rescan on it to force it to find devices. This makes it possible to fail rescan, and also to defer it after construction from both OOM-safety terms and hotplug capabilities.
56 lines
1.7 KiB
C++
56 lines
1.7 KiB
C++
/*
|
|
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <Kernel/Bus/PCI/API.h>
|
|
#include <Kernel/Devices/PCISerialDevice.h>
|
|
#include <Kernel/Sections.h>
|
|
|
|
namespace Kernel {
|
|
|
|
static SerialDevice* s_the = nullptr;
|
|
|
|
UNMAP_AFTER_INIT void PCISerialDevice::detect()
|
|
{
|
|
size_t current_device_minor = 68;
|
|
PCI::enumerate([&](const PCI::Address& address, PCI::ID id) {
|
|
if (address.is_null())
|
|
return;
|
|
|
|
for (auto& board_definition : board_definitions) {
|
|
if (board_definition.device_id != id)
|
|
continue;
|
|
|
|
auto bar_base = PCI::get_BAR(address, board_definition.pci_bar) & ~1;
|
|
auto port_base = IOAddress(bar_base + board_definition.first_offset);
|
|
for (size_t i = 0; i < board_definition.port_count; i++) {
|
|
auto serial_device = new SerialDevice(port_base.offset(board_definition.port_size * i), current_device_minor++);
|
|
if (board_definition.baud_rate != SerialDevice::Baud::Baud38400) // non-default baud
|
|
serial_device->set_baud(board_definition.baud_rate);
|
|
|
|
// If this is the first port of the first pci serial device, store it as the debug PCI serial port (TODO: Make this configurable somehow?)
|
|
if (!is_available())
|
|
s_the = serial_device;
|
|
// NOTE: We intentionally leak the reference to serial_device here, as it is eternal
|
|
}
|
|
|
|
dmesgln("PCISerialDevice: Found {} @ {}", board_definition.name, address);
|
|
return;
|
|
}
|
|
});
|
|
}
|
|
|
|
SerialDevice& PCISerialDevice::the()
|
|
{
|
|
VERIFY(s_the);
|
|
return *s_the;
|
|
}
|
|
|
|
bool PCISerialDevice::is_available()
|
|
{
|
|
return s_the;
|
|
}
|
|
|
|
}
|