/[gentoo-src]/Xorgautoconfig/pci.c
Gentoo

Contents of /Xorgautoconfig/pci.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (show annotations) (download) (as text)
Fri Jan 6 21:19:48 2006 UTC (8 years, 3 months ago) by josejx
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +3 -3 lines
File MIME type: text/x-csrc
Fixed broken mmio check, version 0.2.2

1 /* This file was originally... */
2 /*
3 * $Id: pci.c,v 1.7 2005/10/17 18:15:29 josejx Exp $
4 *
5 * Linux PCI Utilities -- List All PCI Devices
6 *
7 * Copyright (c) 1997--1999 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
8 *
9 * Can be freely distributed and used under the terms of the GNU GPL.
10 */
11 /* So, all the same terms apply but now it's also:
12 * Copyright (c) 2000 Tom Rini <trini@kernel.crashing.org>
13 */
14
15 #include <string.h>
16 #include <stdlib.h>
17 #include <pci/pci.h>
18
19 struct pci_filter filter; /* Device filter */
20 struct pci_access *pacc;
21 int bus, dev, func; /* Location of the card */
22
23 struct device {
24 struct device *next;
25 struct pci_dev *dev;
26 unsigned int config_cnt;
27 u8 config[256];
28 };
29
30 struct device *first_dev;
31
32 struct device *scan_device(struct pci_dev *p)
33 {
34 int how_much = 64;
35 struct device *d;
36
37 if (!pci_filter_match(&filter, p))
38 return NULL;
39 d = malloc(sizeof(struct device));
40 bzero(d, sizeof(*d));
41 d->dev = p;
42 if (!pci_read_block(p, 0, d->config, how_much))
43 exit(1);
44 if (how_much < 128 && (d->config[PCI_HEADER_TYPE] & 0x7f) == PCI_HEADER_TYPE_CARDBUS)
45 {
46 /* For cardbus bridges, we need to fetch 64 bytes more to get the full standard header... */
47 if (!pci_read_block(p, 64, d->config+64, 64))
48 exit(1);
49 how_much = 128;
50 }
51 d->config_cnt = how_much;
52 pci_setup_cache(p, d->config, d->config_cnt);
53 pci_fill_info(p, PCI_FILL_IDENT | PCI_FILL_IRQ | PCI_FILL_BASES | PCI_FILL_ROM_BASE | PCI_FILL_SIZES);
54 return d;
55 }
56 void scan_devices(void)
57 {
58 struct device *d;
59 struct pci_dev *p;
60
61 pci_scan_bus(pacc);
62 for(p=pacc->devices; p; p=p->next)
63 if ((d = scan_device(p)))
64 {
65 d->next = first_dev;
66 first_dev = d;
67 }
68 }
69
70 u16 get_conf_word(struct device *d, unsigned int pos)
71 {
72 return d->config[pos] | (d->config[pos+1] << 8);
73 }
74
75 void findVideoDevice(void)
76 {
77 struct device *d;
78 struct pci_dev *p;
79 u16 w;
80
81 pacc = pci_alloc();
82 pci_filter_init(pacc, &filter);
83 pci_init(pacc);
84 scan_devices();
85
86 for(d=first_dev; d; d=d->next) {
87 p = d->dev;
88 /* See if the current device is a VGA card, if so set vars and break */
89 w = get_conf_word(d, PCI_CLASS_DEVICE) >> 8;
90 if(w == PCI_BASE_CLASS_DISPLAY) {
91 bus = p->bus;
92 dev = p->dev;
93 func = p->func;
94 break;
95 }
96 }
97
98 pci_cleanup(pacc);
99 }

  ViewVC Help
Powered by ViewVC 1.1.20