source: rtems/c/src/lib/libbsp/mips/malta/pci/pcilistdevices.c @ a36d1b4

4.115
Last change on this file since a36d1b4 was a36d1b4, checked in by Jennifer Averett <jennifer.averett@…>, on 04/04/12 at 17:21:15

Add MIPS/Malta BSP.

  • Property mode set to 100644
File size: 2.7 KB
Line 
1/**
2 *  @file
3 *
4 *  I think this file could be made generic and put in a general pci
5 *  area.
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2012.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 */
16
17/*
18 * List all PCI Devices
19 */
20
21#define PCI_INVALID_VENDORDEVICEID  0xffffffff
22#define PCI_MULTI_FUNCTION      0x80
23
24#define PCI_DEBUG
25
26#include <inttypes.h>
27#include <bsp/pci.h>
28#include <rtems/bspIo.h>
29#include <stdio.h>
30
31/*
32 * Make device signature from bus number, device number and function
33 * number
34 */
35#define PCIB_DEVSIG_MAKE(b,d,f) ((b<<8)|(d<<3)|(f))
36
37/*
38 * Extract various parts from device signature
39 */
40#define PCIB_DEVSIG_BUS(x) (((x)>>8) &0xff)
41#define PCIB_DEVSIG_DEV(x) (((x)>>3) & 0x1f)
42#define PCIB_DEVSIG_FUNC(x) ((x) & 0x7)
43
44static int print_device_config(
45   int bus,
46   int dev,
47   int fun
48)
49{
50  uint16_t vi,di;
51  uint16_t cd,st;
52  uint32_t b1,b2;
53  uint8_t  il,ip;
54
55  pci_read_config_word (bus, dev, fun, PCI_VENDOR_ID,      &vi);
56  pci_read_config_word (bus, dev, fun, PCI_DEVICE_ID,      &di);
57  pci_read_config_word (bus, dev, fun, PCI_COMMAND,        &cd);
58  pci_read_config_word (bus, dev, fun, PCI_STATUS,         &st);
59  pci_read_config_dword(bus, dev, fun, PCI_BASE_ADDRESS_0, &b1);
60  pci_read_config_dword(bus, dev, fun, PCI_BASE_ADDRESS_1, &b2);
61  pci_read_config_byte (bus, dev, fun, PCI_INTERRUPT_LINE, &il);
62  pci_read_config_byte (bus, dev, fun, PCI_INTERRUPT_PIN,  &ip);
63
64  printk(
65    "%3d:0x%02x:%d    0x%04x-0x%04x:  0x%04x 0x%04x 0x%08" PRIx32
66        " 0x%08" PRIx32 "       %d -> %3d (=0x%02x)\n",
67     bus, dev, fun, vi, di, cd, st, b1, b2, ip, il, il);
68  return 0;
69}
70
71void pci_list_devices( void )
72{
73   uint32_t d;
74   unsigned char bus,dev,fun,hd;
75
76  printk(
77    "BUS:SLOT:FUN  VENDOR-DEV_ID: COMMAND STATUS BASE_ADDR0 "
78    "BASE_ADDR1 IRQ_PIN -> IRQ_LINE\n"
79  );
80  for (bus=0 ; bus<pci_bus_count(); bus++) {
81    for (dev=0 ; dev<PCI_MAX_DEVICES; dev++) {
82      for (fun=0 ; fun<PCI_MAX_FUNCTIONS; fun++) {
83        /*
84         * The last devfn id/slot is special; must skip it
85         */
86        if (PCI_MAX_DEVICES-1==dev && PCI_MAX_FUNCTIONS-1 == fun)
87          break;
88
89        (void) pci_read_config_dword(bus,dev,0,PCI_VENDOR_ID,&d);
90        if (PCI_INVALID_VENDORDEVICEID == d)
91          continue;
92
93        if ( 0 == fun ) {
94          pci_read_config_byte(bus,dev,0, PCI_HEADER_TYPE, &hd);
95          hd = (hd & PCI_MULTI_FUNCTION ? PCI_MAX_FUNCTIONS : 1);
96        }
97
98        (void)pci_read_config_dword(bus,dev,fun,PCI_VENDOR_ID,&d);
99        if (PCI_INVALID_VENDORDEVICEID == d)
100          continue;
101        print_device_config( bus, dev, fun );
102      }
103    }
104  }
105}
Note: See TracBrowser for help on using the repository browser.