BMIDEChannel.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/OwnPtr.h>
  8. #include <Kernel/Storage/IDEChannel.h>
  9. namespace Kernel {
  10. class AsyncBlockDeviceRequest;
  11. struct [[gnu::packed]] PhysicalRegionDescriptor {
  12. u32 offset;
  13. u16 size { 0 };
  14. u16 end_of_table { 0 };
  15. };
  16. class IDEController;
  17. class BMIDEChannel final : public IDEChannel {
  18. friend class IDEController;
  19. friend class PATADiskDevice;
  20. public:
  21. static NonnullRefPtr<BMIDEChannel> create(const IDEController&, IDEChannel::IOAddressGroup, IDEChannel::ChannelType type);
  22. static NonnullRefPtr<BMIDEChannel> create(const IDEController&, u8 irq, IDEChannel::IOAddressGroup, IDEChannel::ChannelType type);
  23. virtual ~BMIDEChannel() override {};
  24. virtual bool is_dma_enabled() const override { return true; };
  25. private:
  26. BMIDEChannel(const IDEController&, IDEChannel::IOAddressGroup, IDEChannel::ChannelType type);
  27. BMIDEChannel(const IDEController&, u8 irq, IDEChannel::IOAddressGroup, IDEChannel::ChannelType type);
  28. void initialize();
  29. void complete_current_request(AsyncDeviceRequest::RequestResult);
  30. //^ IRQHandler
  31. virtual bool handle_irq(const RegisterState&) override;
  32. //* IDEChannel
  33. virtual void send_ata_io_command(LBAMode lba_mode, Direction direction) const override;
  34. virtual void ata_read_sectors(bool, u16) override;
  35. virtual void ata_write_sectors(bool, u16) override;
  36. PhysicalRegionDescriptor& prdt() { return *reinterpret_cast<PhysicalRegionDescriptor*>(m_prdt_region->vaddr().as_ptr()); }
  37. OwnPtr<Memory::Region> m_prdt_region;
  38. OwnPtr<Memory::Region> m_dma_buffer_region;
  39. RefPtr<Memory::PhysicalPage> m_prdt_page;
  40. RefPtr<Memory::PhysicalPage> m_dma_buffer_page;
  41. };
  42. }