forked from Bananymous/banan-os
Kernel: Rewrite whole device structure
We now have DevFileSystem which is derived from RamFileSystem. All devices are RamInodes. We don't have separate DeviceManager anymore. To iterate over devices, you can loop througn every inode in devfs.
This commit is contained in:
@@ -20,28 +20,28 @@ namespace Kernel
|
||||
};
|
||||
|
||||
public:
|
||||
static ATABus* create(ATAController*, uint16_t base, uint16_t ctrl, uint8_t irq);
|
||||
static ATABus* create(ATAController&, uint16_t base, uint16_t ctrl, uint8_t irq);
|
||||
|
||||
BAN::ErrorOr<void> read(ATADevice*, uint64_t, uint8_t, uint8_t*);
|
||||
BAN::ErrorOr<void> write(ATADevice*, uint64_t, uint8_t, const uint8_t*);
|
||||
BAN::ErrorOr<void> read(ATADevice&, uint64_t, uint8_t, uint8_t*);
|
||||
BAN::ErrorOr<void> write(ATADevice&, uint64_t, uint8_t, const uint8_t*);
|
||||
|
||||
ATAController* controller() { return m_controller; }
|
||||
ATAController& controller() { return m_controller; }
|
||||
|
||||
void on_irq();
|
||||
|
||||
private:
|
||||
ATABus(ATAController* controller, uint16_t base, uint16_t ctrl)
|
||||
ATABus(ATAController& controller, uint16_t base, uint16_t ctrl)
|
||||
: m_controller(controller)
|
||||
, m_base(base)
|
||||
, m_ctrl(ctrl)
|
||||
{}
|
||||
void initialize(uint8_t irq);
|
||||
|
||||
void select_device(const ATADevice*);
|
||||
DeviceType identify(const ATADevice*, uint16_t*);
|
||||
void select_device(const ATADevice&);
|
||||
DeviceType identify(const ATADevice&, uint16_t*);
|
||||
|
||||
void block_until_irq();
|
||||
uint8_t device_index(const ATADevice*) const;
|
||||
uint8_t device_index(const ATADevice&) const;
|
||||
|
||||
uint8_t io_read(uint16_t);
|
||||
void io_write(uint16_t, uint8_t);
|
||||
@@ -51,14 +51,14 @@ namespace Kernel
|
||||
BAN::Error error();
|
||||
|
||||
private:
|
||||
ATAController* m_controller;
|
||||
ATAController& m_controller;
|
||||
const uint16_t m_base;
|
||||
const uint16_t m_ctrl;
|
||||
SpinLock m_lock;
|
||||
|
||||
bool m_has_got_irq { false };
|
||||
|
||||
ATADevice* m_devices[2] { nullptr, nullptr };
|
||||
BAN::RefPtr<ATADevice> m_devices[2] {};
|
||||
|
||||
friend class ATAController;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <kernel/DeviceManager.h>
|
||||
#include <kernel/PCI.h>
|
||||
#include <kernel/SpinLock.h>
|
||||
#include <kernel/Storage/StorageController.h>
|
||||
@@ -13,16 +12,12 @@ namespace Kernel
|
||||
class ATAController final : public StorageController
|
||||
{
|
||||
public:
|
||||
static BAN::ErrorOr<ATAController*> create(const PCIDevice&);
|
||||
static BAN::ErrorOr<BAN::RefPtr<ATAController>> create(const PCIDevice&);
|
||||
|
||||
virtual BAN::Vector<StorageDevice*> devices() override;
|
||||
|
||||
uint8_t next_device_index() const;
|
||||
virtual BAN::Vector<BAN::RefPtr<StorageDevice>> devices() override;
|
||||
|
||||
private:
|
||||
ATAController()
|
||||
: m_rdev(makedev(DeviceManager::get().get_next_rdev(), 0))
|
||||
{ }
|
||||
ATAController();
|
||||
BAN::ErrorOr<void> initialize(const PCIDevice& device);
|
||||
|
||||
private:
|
||||
@@ -35,8 +30,6 @@ namespace Kernel
|
||||
virtual gid_t gid() const override { return 0; }
|
||||
virtual dev_t rdev() const override { return m_rdev; }
|
||||
|
||||
virtual BAN::StringView name() const override { return "hd"sv; }
|
||||
|
||||
virtual BAN::ErrorOr<size_t> read(size_t, void*, size_t) { return BAN::Error::from_errno(ENOTSUP); }
|
||||
|
||||
private:
|
||||
|
||||
@@ -9,10 +9,7 @@ namespace Kernel
|
||||
class ATADevice final : public StorageDevice
|
||||
{
|
||||
public:
|
||||
ATADevice(ATABus* bus)
|
||||
: m_bus(bus)
|
||||
, m_rdev(makedev(DeviceManager::get().get_next_rdev(), 0))
|
||||
{ }
|
||||
ATADevice(ATABus&);
|
||||
BAN::ErrorOr<void> initialize(ATABus::DeviceType, const uint16_t*);
|
||||
|
||||
virtual uint32_t sector_size() const override { return m_sector_words * 2; }
|
||||
@@ -25,7 +22,7 @@ namespace Kernel
|
||||
virtual BAN::ErrorOr<void> write_sectors_impl(uint64_t, uint8_t, const uint8_t*) override;
|
||||
|
||||
private:
|
||||
ATABus* m_bus;
|
||||
ATABus& m_bus;
|
||||
uint8_t m_index;
|
||||
|
||||
ATABus::DeviceType m_type;
|
||||
@@ -44,13 +41,10 @@ namespace Kernel
|
||||
virtual gid_t gid() const override { return 0; }
|
||||
virtual dev_t rdev() const override { return m_rdev; }
|
||||
|
||||
virtual BAN::StringView name() const override { return BAN::StringView(m_device_name, sizeof(m_device_name) - 1); }
|
||||
|
||||
virtual BAN::ErrorOr<size_t> read(size_t, void*, size_t) override;
|
||||
|
||||
public:
|
||||
const dev_t m_rdev;
|
||||
char m_device_name[4] {};
|
||||
};
|
||||
|
||||
}
|
||||
@@ -8,7 +8,10 @@ namespace Kernel
|
||||
class StorageController : public CharacterDevice
|
||||
{
|
||||
public:
|
||||
virtual BAN::Vector<StorageDevice*> devices() = 0;
|
||||
StorageController()
|
||||
: CharacterDevice(0660, 0, 0)
|
||||
{ }
|
||||
virtual BAN::Vector<BAN::RefPtr<StorageDevice>> devices() = 0;
|
||||
};
|
||||
|
||||
}
|
||||
@@ -48,20 +48,20 @@ namespace Kernel
|
||||
virtual Mode mode() const override { return { Mode::IFBLK | Mode::IRUSR | Mode::IRGRP }; }
|
||||
virtual uid_t uid() const override { return 0; }
|
||||
virtual gid_t gid() const override { return 0; }
|
||||
virtual dev_t rdev() const override;
|
||||
|
||||
virtual BAN::StringView name() const override { return m_device_name; }
|
||||
virtual dev_t rdev() const override { return m_rdev; }
|
||||
|
||||
virtual BAN::ErrorOr<size_t> read(size_t, void*, size_t) override;
|
||||
|
||||
|
||||
private:
|
||||
const uint32_t m_index;
|
||||
BAN::String m_device_name;
|
||||
const dev_t m_rdev;
|
||||
};
|
||||
|
||||
class StorageDevice : public BlockDevice
|
||||
{
|
||||
public:
|
||||
StorageDevice()
|
||||
: BlockDevice(0660, 0, 0)
|
||||
{ }
|
||||
virtual ~StorageDevice();
|
||||
|
||||
BAN::ErrorOr<void> initialize_partitions();
|
||||
@@ -74,7 +74,7 @@ namespace Kernel
|
||||
|
||||
BAN::Vector<Partition*>& partitions() { return m_partitions; }
|
||||
const BAN::Vector<Partition*>& partitions() const { return m_partitions; }
|
||||
|
||||
|
||||
protected:
|
||||
virtual BAN::ErrorOr<void> read_sectors_impl(uint64_t lba, uint8_t sector_count, uint8_t* buffer) = 0;
|
||||
virtual BAN::ErrorOr<void> write_sectors_impl(uint64_t lba, uint8_t sector_count, const uint8_t* buffer) = 0;
|
||||
|
||||
Reference in New Issue
Block a user