inteltool: add --ahci for printing AHCI registers

According to datasheets for Intel ICH/PCH, it works for chipsets from
ICH7 to 9-series PCH, with PCI device address D31:F2.

Change-Id: If1ddd7208108bda949b5a94894a7bf9e8bfe1e5f
Signed-off-by: Iru Cai <mytbk920423@gmail.com>
Reviewed-on: https://review.coreboot.org/15106
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
diff --git a/util/inteltool/inteltool.c b/util/inteltool/inteltool.c
index 063efb7..c7ca631 100644
--- a/util/inteltool/inteltool.c
+++ b/util/inteltool/inteltool.c
@@ -215,12 +215,13 @@
 
 void print_usage(const char *name)
 {
-	printf("usage: %s [-vh?gGrpmedPMaAsfS]\n", name);
+	printf("usage: %s [-vh?gGrpmedPMaAsfSR]\n", name);
 	printf("\n"
 	     "   -v | --version:                   print the version\n"
 	     "   -h | --help:                      print this help\n\n"
 	     "   -s | --spi:                       dump southbridge spi and bios_cntrl registers\n"
 	     "   -f | --gfx:                       dump graphics registers (UNSAFE: may hang system!)\n"
+	     "   -R | --ahci:                      dump AHCI registers\n"
 	     "   -g | --gpio:                      dump southbridge GPIO registers\n"
 	     "   -G | --gpio-diffs:                show GPIO differences from defaults\n"
 	     "   -r | --rcba:                      dump southbridge RCBA registers\n"
@@ -240,7 +241,7 @@
 int main(int argc, char *argv[])
 {
 	struct pci_access *pacc;
-	struct pci_dev *sb = NULL, *nb, *gfx = NULL, *dev;
+	struct pci_dev *sb = NULL, *nb, *gfx = NULL, *ahci = NULL, *dev;
 	const char *dump_spd_file = NULL;
 	int i, opt, option_index = 0;
 	unsigned int id;
@@ -250,7 +251,7 @@
 	int dump_gpios = 0, dump_mchbar = 0, dump_rcba = 0;
 	int dump_pmbase = 0, dump_epbar = 0, dump_dmibar = 0;
 	int dump_pciexbar = 0, dump_coremsrs = 0, dump_ambs = 0;
-	int dump_spi = 0, dump_gfx = 0;
+	int dump_spi = 0, dump_gfx = 0, dump_ahci = 0;
 	int show_gpio_diffs = 0;
 
 	static struct option long_options[] = {
@@ -270,10 +271,11 @@
 		{"spd", 0, 0, 'S'},
 		{"all", 0, 0, 'a'},
 		{"gfx", 0, 0, 'f'},
+		{"ahci", 0, 0, 'R'},
 		{0, 0, 0, 0}
 	};
 
-	while ((opt = getopt_long(argc, argv, "vh?gGrpmedPMaAsfS:",
+	while ((opt = getopt_long(argc, argv, "vh?gGrpmedPMaAsfRS:",
                                   long_options, &option_index)) != EOF) {
 		switch (opt) {
 		case 'v':
@@ -290,6 +292,9 @@
 		case 'f':
 			dump_gfx = 1;
 			break;
+		case 'R':
+			dump_ahci = 1;
+			break;
 		case 'G':
 			show_gpio_diffs = 1;
 			break;
@@ -326,6 +331,7 @@
 			dump_coremsrs = 1;
 			dump_ambs = 1;
 			dump_spi = 1;
+			dump_ahci = 1;
 			break;
 		case 'A':
 			dump_ambs = 1;
@@ -422,6 +428,15 @@
 			gfx = 0;
 	}
 
+	ahci = pci_get_dev(pacc, 0, 0, 0x1f, 2);
+
+	if (ahci) {
+		pci_fill_info(ahci, PCI_FILL_IDENT|PCI_FILL_BASES|PCI_FILL_SIZES|PCI_FILL_CLASS);
+
+		if (ahci->vendor_id != PCI_VENDOR_ID_INTEL)
+			ahci = 0;
+	}
+
 	id = cpuid(1);
 
 	/* Intel has suggested applications to display the family of a CPU as
@@ -515,6 +530,10 @@
 		print_gfx(gfx);
 	}
 
+	if (dump_ahci) {
+		print_ahci(ahci);
+	}
+
 	/* Clean up */
 	pci_free_dev(nb);
 	// pci_free_dev(sb); // TODO: glibc detected "double free or corruption"