ata.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #include <asm/port_io.h>
  3. #include <kernel/hw/port.hpp>
  4. #include <kernel/syscall.hpp>
  5. #include <types/cplusplus.hpp>
  6. constexpr port_id_t ATA_PRIMARY_BUS_BASE = 0x1f0;
  7. constexpr port_id_t ATA_PRIMARY_BUS_DEV_CONTROL_OR_ALTER_STATUS = 0x1f0;
  8. constexpr port_id_t ATA_SECONDARY_BUS_BASE = 0x170;
  9. constexpr port_id_t ATA_SECONDARY_BUS_DEV_CONTROL_OR_ALTER_STATUS = 0x1f0;
  10. namespace hw {
  11. class ata {
  12. public:
  13. union stat_t {
  14. uint8_t v;
  15. struct {
  16. uint8_t err : 1;
  17. uint8_t idx : 1;
  18. uint8_t corr : 1;
  19. uint8_t drq : 1;
  20. uint8_t srv : 1;
  21. uint8_t df : 1;
  22. uint8_t rdy : 1;
  23. uint8_t bsy : 1;
  24. } in;
  25. };
  26. private:
  27. p16 data;
  28. p16r error;
  29. p16w feats;
  30. p8 count;
  31. p8 lbalo;
  32. p8 lbami;
  33. p8 lbahi;
  34. p8 drive;
  35. p8r stats;
  36. p8w comms;
  37. uint8_t slave_flag;
  38. public:
  39. ata(port_id_t port_base);
  40. stat_t status(void) const;
  41. bool identify(void) const;
  42. int select(bool master);
  43. size_t read_data(char* buf, size_t n) const;
  44. size_t write_data(const char* buf, size_t n) const;
  45. int read_sector(char* buf, uint32_t lba_low, uint16_t lba_high) const;
  46. int write_sector(const char* buf, uint32_t lba_low, uint16_t lba_high) const;
  47. };
  48. void NORETURN init_ata(void* data);
  49. } // namespace hw