serenity/Kernel/Devices/Storage/SD/PCISDHostController.h
Liav A 500b7b08d6 Kernel: Move the Storage directory to be a new directory under Devices
The Storage subsystem, like the Audio and HID subsystems, exposes Unix
device files (for example, in the /dev directory). To ensure consistency
across the repository, we should make the Storage subsystem to reside in
the Kernel/Devices directory like the two other mentioned subsystems.
2023-06-02 11:04:37 +02:00

50 lines
1.4 KiB
C++

/*
* 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/Devices/Storage/SD/SDHostController.h>
#include <Kernel/Memory/TypedMapping.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;
};
}