source: rtems/c/src/lib/libbsp/powerpc/mvme5500/network/if_1GHz/pci_map.c @ ac7af4a

4.104.115
Last change on this file since ac7af4a was ac7af4a, checked in by Ralf Corsepius <ralf.corsepius@…>, on 11/30/09 at 04:37:44

Whitespace removal.

  • Property mode set to 100644
File size: 3.6 KB
Line 
1/*      $NetBSD: pci_map.c,v 1.12 2002/05/30 12:06:43 drochner Exp $    */
2
3/*-
4 * Copyright (c) 2004, 2005  Brookhaven National  Laboratory
5 *               S. Kate Feng <feng1@bnl.gov>
6 *
7 * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
8 * All rights reserved.
9 *
10 * This code is derived from software contributed to The NetBSD Foundation
11 * by Charles M. Hannum; by William R. Studenmund; by Jason R. Thorpe.
12 *
13 */
14
15/*
16 * PCI device mapping.
17 */
18
19#include <sys/cdefs.h>
20#include <sys/param.h>
21#include <sys/systm.h>
22#include <rtems/rtems/types.h>
23
24#include <bsp/pci.h>
25#include <bsp/pcireg.h>
26
27extern int pci_get_capability(int b, int d, int f, int capid,int *offset,uint32_t *value);
28extern int pci_mem_find(int b, int d, int f, int reg, unsigned *basep,unsigned *sizep);
29extern int pci_io_find(int b, int d, int f, int reg,unsigned *basep,unsigned *sizep);
30
31int pci_io_find(int b, int d, int f, int reg,unsigned *basep,unsigned *sizep)
32{
33  uint32_t address, mask;
34
35  if (reg < PCI_MAPREG_START ||
36#if 0
37            /*
38             * Can't do this check; some devices have mapping registers
39             * way out in left field.
40             */
41            reg >= PCI_MAPREG_END ||
42#endif
43            (reg & 3))
44                rtems_panic("pci_io_find: bad request");
45
46  /*
47   * Section 6.2.5.1, `Address Maps', tells us that:
48   *
49   * 1) The builtin software should have already mapped the device in a
50   * reasonable way.
51   *
52   * 2) A device which wants 2^n bytes of memory will hardwire the bottom
53   * n bits of the address to 0.  As recommended, we write all 1s and see
54   * what we get back.
55   */
56  pci_read_config_dword(b,d,f,reg, &address);
57  if ( !(address & PCI_MAPREG_TYPE_IO)) return(1);
58  pci_write_config_dword(b,d,f,reg, 0xffffffff);
59  pci_read_config_dword(b,d,f,reg,&mask);
60  pci_write_config_dword(b,d,f,reg, address);
61
62  if ( (*sizep = PCI_MAPREG_IO_SIZE(mask))== 0) {
63     printk("pci_io_find: void region\n");
64     return(1);
65  }
66  *basep = PCI_MAPREG_IO_ADDR(address);
67  return(0);
68}
69
70int pci_mem_find(int b, int d, int f, int reg, unsigned *basep,unsigned *sizep)
71{
72  uint32_t address, mask;
73
74  if (reg < PCI_MAPREG_START ||
75#if 0
76            /*
77             * Can't do this check; some devices have mapping registers
78             * way out in left field.
79             */
80            reg >= PCI_MAPREG_END ||
81#endif
82            (reg & 3))
83      rtems_panic("pci_mem_find: bad request");
84
85  pci_read_config_dword(b,d,f,reg, &address);
86  if (address & PCI_MAPREG_TYPE_IO) {
87     printk("pci_mem_find: expected type mem, found I/O\n");
88     return(1);
89  }
90
91  /*
92   * Section 6.2.5.1, `Address Maps', tells us that:
93   *
94   * 1) The builtin software should have already mapped the device in a
95   * reasonable way.
96   *
97   * 2) A device which wants 2^n bytes of memory will hardwire the bottom
98   * n bits of the address to 0.  As recommended, we write all 1s and see
99   * what we get back.
100   */
101  pci_write_config_dword(b,d,f,reg, 0xffffffff);
102  pci_read_config_dword(b,d,f,reg,&mask);
103  pci_write_config_dword(b,d,f,reg, address);
104  if ( (*sizep = PCI_MAPREG_MEM_SIZE(mask))== 0) {
105     printk("pci_io_find: void region\n");
106     return (1);
107  }
108  *basep = PCI_MAPREG_MEM_ADDR(address);
109  return(0);
110}
111
112int pci_get_capability(int b, int d, int f, int capid,int *offset,uint32_t *value)
113{
114  uint32_t reg, ofs;
115
116  /*  i82544EI PCI_CAPLISTPTR_REG */
117  pci_read_config_dword(b,d,f,PCI_CAPLISTPTR_REG, &reg);
118  ofs = PCI_CAPLIST_PTR(reg);
119  while (ofs != 0) {
120#ifdef DIAGNOSTIC
121    if ((ofs & 3) || (ofs < 0x40))
122       panic("pci_get_capability");
123#endif
124    pci_read_config_dword(b,d,f,ofs, &reg);
125    if (PCI_CAPLIST_CAP(reg) == capid) {
126       if (offset)
127           *offset = ofs;
128       if (value)
129           *value = reg;
130       return (1);
131    }
132    ofs = PCI_CAPLIST_NEXT(reg);
133  }
134  return (0);
135}
Note: See TracBrowser for help on using the repository browser.