The Pedigree Project 0.1
AhciController.h
1/*
2 * Copyright (c) 2026, Pedigree Developers
3 * SPDX-License-Identifier: ISC
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16#ifndef AHCI_CONTROLLER_H
17#define AHCI_CONTROLLER_H
18#include "pedigree/kernel/machine/Disk.h"
19#include "pedigree/kernel/machine/IrqHandler.h"
20#include "pedigree/kernel/process/Mutex.h"
21
22#include "modules/drivers/common/scsi/ScsiController.h"
23class AhciPort;
24class IoBase;
26 public:
27 explicit AhciController(Device* pci);
28 ~AhciController() override;
29 bool initialiseController();
30 bool supportsConcurrentReads() const override {
31 return true;
32 }
33 void shutdown();
34 bool identify(size_t port, uint16_t* words, bool interruptProbe = false);
35 EXPORTED_PUBLIC bool readWrite(size_t port, uint64_t lba, uint16_t sectors, void* buffer,
36 size_t bytes, bool write);
37 bool readBatch(size_t port, Disk::ReadBuffer* buffers, size_t count);
38 bool writeBatch(size_t port, Disk::WriteBuffer* buffers, size_t count);
39 bool flush(size_t port, bool extended);
40 void configureDisk(size_t port, size_t sectorBytes, size_t queueDepth);
41 EXPORTED_PUBLIC size_t interruptCompletions() const;
42 EXPORTED_PUBLIC size_t maximumOutstanding(size_t port) const;
43 IrqDisposition irq(irq_id_t number) override;
44 bool sendCommand(size_t, uintptr_t, uint8_t, uintptr_t, uint16_t, bool) override {
45 return false;
46 }
47
48 protected:
49 size_t getNumUnits() override {
50 return getNumChildren();
51 }
52
53 private:
54 bool claimOwnership(uint32_t version);
55 bool reset();
56 Device* m_Pci;
57 IoBase* m_Registers;
58 AhciPort* m_Ports[32];
59 mutable Mutex m_IrqLock;
60 irq_id_t m_Irq;
61 uint32_t m_Implemented;
62 uint16_t m_OriginalCommand;
63 bool m_PciChanged;
64 bool m_HardwareOwned;
65 bool m_Interrupts;
66 bool m_Stopping;
67 bool m_Shutdown;
68};
69#endif
bool supportsConcurrentReads() const override
IrqDisposition irq(irq_id_t number) override
size_t getNumChildren()
Definition Device.cc:131
Abstrace base class for hardware I/O capabilities.
Definition IoBase.h:32
Definition Mutex.h:56
IrqDisposition
Definition IrqHandler.h:31