ahci.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /* AHCI (SATA) driver: polled, no IRQs, no NCQ.
  2. * Finds the first AHCI controller (PCI class 01:06:01), brings its ports up
  3. * and exposes the attached ATA disks. Read/write use DMA (READ/WRITE DMA EXT,
  4. * LBA48) through a bounce buffer. */
  5. #ifndef AHCI_H
  6. #define AHCI_H
  7. #define AHCI_MAX_DISKS 8
  8. struct ahci_disk {
  9. unsigned int port; /* controller port number */
  10. unsigned int sectors; /* total sectors (clamped to 32 bits) */
  11. char model[41];
  12. };
  13. /* Initialise the first AHCI controller (register window + DMA areas). Ports
  14. * are brought up lazily by ahci_scan(), so empty ports cost nothing at boot.
  15. * Idempotent; returns 0 if a controller was found and brought up, -1
  16. * otherwise. */
  17. int ahci_init(void);
  18. /* 1 if an AHCI controller was found and initialised. */
  19. int ahci_controller_present(void);
  20. /* Collect present ATA disks. Returns the number written (<= max). */
  21. unsigned int ahci_scan(struct ahci_disk *out, unsigned int max);
  22. /* Read/write `count` sectors at LBA `lba` on the given controller port.
  23. * Return 0 on success, -1 on error. */
  24. int ahci_read_sectors(unsigned int port, unsigned int lba, void *buf, unsigned int count);
  25. int ahci_write_sectors(unsigned int port, unsigned int lba, const void *buf, unsigned int count);
  26. /* Flush the port's write cache (FLUSH CACHE EXT). */
  27. int ahci_flush(unsigned int port);
  28. #endif