mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:37:35 +00:00
Kernel: Add support for SD host controllers on the PCI bus
This commit is contained in:
parent
47cae8005f
commit
5fe6c6fc24
5 changed files with 124 additions and 5 deletions
50
Kernel/Storage/SD/PCISDHostController.h
Normal file
50
Kernel/Storage/SD/PCISDHostController.h
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2023, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Kernel/Bus/PCI/API.h>
|
||||
#include <Kernel/Bus/PCI/Device.h>
|
||||
#include <Kernel/Memory/TypedMapping.h>
|
||||
#include <Kernel/Storage/SD/SDHostController.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class PCISDHostController : public PCI::Device
|
||||
, public SDHostController {
|
||||
public:
|
||||
static ErrorOr<NonnullRefPtr<PCISDHostController>> try_initialize(PCI::DeviceIdentifier const& device_identifier);
|
||||
|
||||
// ^PCI::Device
|
||||
virtual StringView device_name() const override { return "SD Host Controller"sv; }
|
||||
|
||||
protected:
|
||||
// ^SDHostController
|
||||
virtual SD::HostControlRegisterMap volatile* get_register_map_base_address() override { return m_registers.ptr(); }
|
||||
|
||||
private:
|
||||
PCISDHostController(PCI::DeviceIdentifier const& device_identifier);
|
||||
|
||||
struct [[gnu::packed]] SlotInformationRegister {
|
||||
u8 first_bar_number : 3;
|
||||
u8 : 1;
|
||||
u8 number_of_slots : 3;
|
||||
u8 : 1;
|
||||
|
||||
u8 slots_available() const { return number_of_slots + 1; }
|
||||
};
|
||||
static_assert(AssertSize<SlotInformationRegister, 1>());
|
||||
|
||||
SlotInformationRegister read_slot_information() const
|
||||
{
|
||||
SpinlockLocker locker(device_identifier().operation_lock());
|
||||
return bit_cast<SlotInformationRegister>(PCI::Access::the().read8_field(device_identifier(), 0x40));
|
||||
}
|
||||
|
||||
Memory::TypedMapping<SD::HostControlRegisterMap volatile> m_registers;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue