Rev 1181 | Rev 1324 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1181 | Rev 1301 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | /* |
1 | /* |
2 | * Copyright (C) 2006 Jakub Jermar |
- | |
3 | * All rights reserved. |
2 | * HelenOS PCI driver. |
4 | * |
3 | * |
5 | * Redistribution and use in source and binary forms, with or without |
4 | * Copyright (C) 1997-2003 Martin Mares |
6 | * modification, are permitted provided that the following conditions |
5 | * Copyright (C) 2006 Jakub Jermar |
7 | * are met: |
- | |
8 | * |
6 | * |
9 | * - Redistributions of source code must retain the above copyright |
7 | * (Based on libpci example.c written by Martin Mares.) |
10 | * notice, this list of conditions and the following disclaimer. |
- | |
11 | * - Redistributions in binary form must reproduce the above copyright |
- | |
12 | * notice, this list of conditions and the following disclaimer in the |
- | |
13 | * documentation and/or other materials provided with the distribution. |
- | |
14 | * - The name of the author may not be used to endorse or promote products |
- | |
15 | * derived from this software without specific prior written permission. |
- | |
16 | * |
8 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
- | |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
- | |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
- | |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
- | |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
- | |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
- | |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
- | |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
- | |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
- | |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
9 | * Can be freely distributed and used under the terms of the GNU GPL. |
27 | */ |
10 | */ |
28 | 11 | ||
29 | #include <ipc.h> |
- | |
30 | #include <stdio.h> |
12 | #include <stdio.h> |
31 | #include <ddi.h> |
13 | #include <ddi.h> |
32 | #include <task.h> |
14 | #include <task.h> |
33 | #include <stdlib.h> |
15 | #include <stdlib.h> |
34 | 16 | ||
- | 17 | #include "libpci/pci.h" |
|
- | 18 | ||
- | 19 | #define PCI_CONF1 0xcf8 |
|
- | 20 | #define PCI_CONF1_SIZE 8 |
|
- | 21 | ||
35 | int main(int argc, char *argv[]) |
22 | int main(int argc, char *argv[]) |
36 | { |
23 | { |
- | 24 | struct pci_access *pacc; |
|
- | 25 | struct pci_dev *dev; |
|
- | 26 | unsigned int c; |
|
- | 27 | char buf[80]; |
|
- | 28 | ||
37 | printf("HelenOS PCI driver\n"); |
29 | printf("HelenOS PCI driver\n"); |
- | 30 | ||
- | 31 | /* |
|
- | 32 | * Gain control over PCI configuration ports. |
|
- | 33 | */ |
|
- | 34 | iospace_enable(task_get_id(), (void *) PCI_CONF1, PCI_CONF1_SIZE); |
|
- | 35 | ||
- | 36 | pacc = pci_alloc(); /* Get the pci_access structure */ |
|
- | 37 | pci_init(pacc); /* Initialize the PCI library */ |
|
- | 38 | pci_scan_bus(pacc); /* We want to get the list of devices */ |
|
- | 39 | for(dev=pacc->devices; dev; dev=dev->next) { /* Iterate over all devices */ |
|
- | 40 | pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES); /* Fill in header info we need */ |
|
- | 41 | c = pci_read_word(dev, PCI_CLASS_DEVICE); /* Read config register directly */ |
|
- | 42 | printf("%02x:%02x.%d vendor=%04x device=%04x class=%04x irq=%d base0=%lx\n", |
|
- | 43 | dev->bus, dev->dev, dev->func, dev->vendor_id, dev->device_id, |
|
- | 44 | c, dev->irq, dev->base_addr[0]); |
|
- | 45 | printf("\t%s\n", pci_lookup_name(pacc, buf, sizeof(buf), PCI_LOOKUP_VENDOR | PCI_LOOKUP_DEVICE, |
|
- | 46 | dev->vendor_id, dev->device_id)); |
|
- | 47 | } |
|
- | 48 | pci_cleanup(pacc); /* Close everything */ |
|
- | 49 | ||
38 | return 0; |
50 | return 0; |
39 | } |
51 | } |