The Pedigree Project 0.1
ahci/Registers.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_REGISTERS_H
17#define AHCI_REGISTERS_H
18#include "pedigree/kernel/processor/types.h"
19
20// Intel AHCI 1.3.1, sections 3 and 4. Direct SATA command lists.
21namespace Ahci {
22constexpr size_t Cap = 0x00, Ghc = 0x04, Is = 0x08, Pi = 0x0c, Vs = 0x10;
23constexpr size_t CccCtl = 0x14, Cap2 = 0x24, Bohc = 0x28;
24constexpr uint32_t Enable = 1U << 31, InterruptEnable = 1U << 1, Reset = 1U;
25constexpr uint32_t StaggeredSpinup = 1U << 27;
26constexpr size_t PortBase = 0x100, PortStride = 0x80;
27constexpr size_t Clb = 0x00, Clbu = 0x04, Fb = 0x08, Fbu = 0x0c;
28constexpr size_t PortIs = 0x10, PortIe = 0x14, Cmd = 0x18, Tfd = 0x20;
29constexpr size_t Sig = 0x24, Ssts = 0x28, Sctl = 0x2c, Serr = 0x30;
30constexpr size_t Sact = 0x34, Ci = 0x38, Devslp = 0x44;
31constexpr uint32_t Start = 1U, Spinup = 1U << 1, PowerOn = 1U << 2;
32constexpr uint32_t FisEnable = 1U << 4, FisRunning = 1U << 14, CommandRunning = 1U << 15;
33constexpr uint32_t ColdPresence = 1U << 20, Atapi = 1U << 24;
34constexpr uint32_t AggressivePower = (1U << 26) | (1U << 27);
35constexpr uint32_t IccMask = 15U << 28, IccActive = 1U << 28;
36constexpr uint32_t Busy = 1U << 7, DataRequest = 1U << 3;
37constexpr uint32_t TaskError = 1U, DeviceFault = 1U << 5;
38constexpr uint32_t TaskFileError = 1U << 30;
39constexpr uint32_t PortErrors = (0x1fU << 26) | (1U << 24) | (1U << 23) | (1U << 4);
40constexpr uint32_t PortInterrupts =
41 PortErrors | (1U << 22) | (1U << 6) | (1U << 3) | (1U << 1) | 1U;
42constexpr uint32_t SataDisk = 0x00000101;
43constexpr size_t MaxTransfer = 64 * 1024;
44constexpr size_t FisOffset = 1024, TableOffset = 1280, TableStride = 384;
45
47 uint32_t flags;
48 volatile uint32_t transferred;
49 uint32_t table;
50 uint32_t tableUpper;
51 uint32_t reserved[4];
52};
53struct Prd {
54 uint32_t address;
55 uint32_t addressUpper;
56 uint32_t reserved;
57 uint32_t byteCount;
58};
60 uint8_t fis[64];
61 uint8_t atapi[16];
62 uint8_t reserved[48];
63 Prd data[16];
64};
65static_assert(sizeof(CommandHeader) == 32, "AHCI command header size");
66static_assert(sizeof(Prd) == 16, "AHCI physical region descriptor size");
67static_assert(sizeof(CommandTable) == 384, "AHCI command table with sixteen PRDs");
68static_assert((FisOffset % 256) == 0 && (TableOffset % 128) == 0, "AHCI DMA alignment");
69} // namespace Ahci
70#endif