blob: 4721461ceef8c50aaf18eda9b30ccb97789f43a8 [file] [log] [blame]
Alexandru Gagniuc67f556c2012-08-10 03:55:42 -05001/*
2 * viatool - dump all registers on a VIA CPU + chipset based system.
3 *
4 * Copyright (C) 2013 Alexandru Gagniuc
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
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Alexandru Gagniuc67f556c2012-08-10 03:55:42 -050015 */
16
17#include "quirks.h"
18#include <viatool.h>
19#include <stdio.h>
20#include <stddef.h>
21
22extern struct quirk_list vx900_sb_quirk_list;
23
24struct quirk_list *sb_quirks[] = {
25 &vx900_sb_quirk_list,
26 0,
27};
28
29struct quirk_list *nb_quirks[] = {
30 0,
31};
32
33int print_quirks(struct pci_dev *sb, struct pci_access *pacc,
34 struct quirk_list **qlists);
35
36int print_quirks_north(struct pci_dev *nb, struct pci_access *pacc)
37{
38 printf("\n====== Northbridge Quirks =======\n\n");
39 return print_quirks(nb, pacc, nb_quirks);
40}
41
42int print_quirks_south(struct pci_dev *sb, struct pci_access *pacc)
43{
44 printf("\n====== Southbridge Quirks =======\n\n");
45 return print_quirks(sb, pacc, sb_quirks);
46}
47
48int print_quirks(struct pci_dev *sb, struct pci_access *pacc,
49 struct quirk_list **qlists)
50{
51 size_t i, j;
52 struct quirk *q;
53 struct quirk_list *qlist;
54 struct pci_dev *dev;
55
56 for (i = 0; ; i++)
57 {
58 qlist = qlists[i];
59
60 if (qlist == NULL) {
61 /* OOPS. We've tried all we know, but no quirk */
62 printf("No quirks supported.\n");
63 break;
64 }
65
66 /* Is this the right device ? */
67 if ( (qlist->pci_vendor_id != sb->vendor_id) ||
68 qlist->pci_device_id != sb->device_id)
69 continue;
70
71 for (j = 0; ; j++)
72 {
73 q = &qlist->dev_quirks[j];
74
75 if(q->pci_device_id == 0)
76 break;
77
78 printf("Probing PCI device %i:%.2x.%i\n",
79 q->pci_bus, q->pci_dev, q->pci_func);
80
81 dev = pci_get_dev(pacc, q->pci_domain, q->pci_bus,
82 q->pci_dev, q->pci_func);
83
84 if (!dev) {
85 perror("Error: no device found\n");
86 continue;
87 }
88
89 pci_fill_info(dev, PCI_FILL_IDENT |
90 PCI_FILL_BASES |
91 PCI_FILL_SIZES |
92 PCI_FILL_CLASS );
93
94 if (dev->device_id != q->pci_device_id) {
95 printf("Expected %.4x:%.4x, got %.4x:%.4x\n",
96 q->pci_vendor_id, q->pci_device_id,
97 dev->vendor_id, dev->device_id);
98 continue;
99 }
100
101 if (!q->quirk_func) {
102 perror("BUG: Quirk missing.\n");
103 continue;
104 }
105
106 q->quirk_func(dev);
107 /* On to next quirk */
108 }
109
110 /* Done. No need to go through the remainder of the list */
111 break;
112 }
113
114 return 0;
115}