Iru Cai | 904538b | 2016-06-08 22:39:22 +0800 | [diff] [blame] | 1 | /* |
| 2 | * ahci.c: dump AHCI registers |
| 3 | * |
| 4 | * Copyright (C) 2016 Iru Cai |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of the |
| 9 | * License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | */ |
| 16 | |
| 17 | #include <stdio.h> |
| 18 | #include <stdlib.h> |
| 19 | #include <inttypes.h> |
| 20 | #include "inteltool.h" |
| 21 | |
| 22 | #define NUM_SATA_PORTS 6 |
| 23 | #define MMIO_SIZE 0x400 |
| 24 | |
| 25 | static const char *ghc_regs[] = { |
| 26 | "CAP", "GHC", "IS", "PI", |
| 27 | "VS", "CCC_CTL", "CCC_PORTS", "EM_LOC", |
| 28 | "EM_CTL", "CAP2", "BOHC" |
| 29 | }; |
| 30 | |
| 31 | static const char *port_ctl_regs[] = { |
| 32 | "PxCLB", "PxCLBU", "PxFB", "PxFBU", |
| 33 | "PxIS", "PxIE", "PxCMD", "Reserved", |
| 34 | "PxTFD", "PxSIG", "PxSSTS", "PxSCTL", |
| 35 | "PxSERR", "PxSACT", "PxCI", "PxSNTF", |
| 36 | "PxFBS", "PxDEVSLP", "Reserved" |
| 37 | }; |
| 38 | |
| 39 | #define NUM_GHC (sizeof(ghc_regs)/sizeof(ghc_regs[0])) |
| 40 | #define NUM_PORTCTL (sizeof(port_ctl_regs)/sizeof(port_ctl_regs[0])) |
| 41 | |
| 42 | int print_ahci(struct pci_dev *ahci) |
| 43 | { |
| 44 | uint64_t mmio_phys; |
| 45 | uint8_t *mmio; |
| 46 | uint32_t i, j; |
| 47 | if (!ahci) { |
| 48 | puts("No SATA device found"); |
| 49 | return 0; |
| 50 | } |
| 51 | printf("\n============= AHCI Registers ==============\n\n"); |
| 52 | mmio_phys = ahci->base_addr[5] & ~0x7ULL; |
| 53 | printf("ABAR = 0x%08llx (MEM)\n\n", (unsigned long long)mmio_phys); |
| 54 | mmio = map_physical(mmio_phys, MMIO_SIZE); |
| 55 | if (mmio == NULL) { |
| 56 | perror("Error mapping MMIO"); |
| 57 | exit(1); |
| 58 | } |
| 59 | |
| 60 | puts("Generic Host Control Registers:"); |
| 61 | for (i = 0; i < 0x100; i += 4) { |
| 62 | printf("0x%02x: 0x%08x (%s)\n", i, *(uint32_t *)(mmio + i), |
| 63 | (i / 4 < NUM_GHC) ? ghc_regs[i / 4]:"Reserved"); |
| 64 | } |
| 65 | |
| 66 | for (i = 0; i < NUM_SATA_PORTS; i++) { |
| 67 | printf("\nPort %d Control Registers:\n", i); |
| 68 | uint8_t *mmio_port = mmio + 0x100 + i * 0x80; |
| 69 | for (j = 0; j < 0x80; j += 4) { |
| 70 | printf("0x%03x: 0x%08x (%s)\n", 0x100+i*0x80+j, *(uint32_t *)(mmio_port + j), |
| 71 | (j / 4 < NUM_PORTCTL) ? port_ctl_regs[j / 4]:"Reserved"); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | unmap_physical((void *)mmio, MMIO_SIZE); |
| 76 | return 0; |
| 77 | } |