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

4.104.114.84.95
Last change on this file since 07e76b9b was 07e76b9b, checked in by Joel Sherrill <joel.sherrill@…>, on 09/14/07 at 15:14:36

2007-09-14 Joel Sherrill <joel.sherrill@…>

  • network/if_1GHz/if_wm.c, network/if_1GHz/pci_map.c: Remove a few warnings.
  • Property mode set to 100644
File size: 3.4 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
27int pci_io_find(int b, int d, int f, int reg,unsigned *basep,unsigned *sizep)
28{
29  uint32_t address, mask;
30
31  if (reg < PCI_MAPREG_START ||
32#if 0
33            /*
34             * Can't do this check; some devices have mapping registers
35             * way out in left field.
36             */
37            reg >= PCI_MAPREG_END ||
38#endif
39            (reg & 3))
40                rtems_panic("pci_io_find: bad request");
41
42  /*
43   * Section 6.2.5.1, `Address Maps', tells us that:
44   *
45   * 1) The builtin software should have already mapped the device in a
46   * reasonable way.
47   *
48   * 2) A device which wants 2^n bytes of memory will hardwire the bottom
49   * n bits of the address to 0.  As recommended, we write all 1s and see
50   * what we get back.
51   */
52  pci_read_config_dword(b,d,f,reg, &address);
53  if ( !(address & PCI_MAPREG_TYPE_IO)) return(1);
54  pci_write_config_dword(b,d,f,reg, 0xffffffff);
55  pci_read_config_dword(b,d,f,reg,&mask);
56  pci_write_config_dword(b,d,f,reg, address);
57
58  if ( (*sizep = PCI_MAPREG_IO_SIZE(mask))== 0) {
59     printk("pci_io_find: void region\n");
60     return(1);
61  }
62  *basep = PCI_MAPREG_IO_ADDR(address);
63  return(0);
64}
65
66int pci_mem_find(int b, int d, int f, int reg, unsigned *basep,unsigned *sizep)
67{
68  uint32_t address, mask;
69
70  if (reg < PCI_MAPREG_START ||
71#if 0
72            /*
73             * Can't do this check; some devices have mapping registers
74             * way out in left field.
75             */
76            reg >= PCI_MAPREG_END ||
77#endif
78            (reg & 3))
79      rtems_panic("pci_mem_find: bad request");
80
81  pci_read_config_dword(b,d,f,reg, &address);
82  if (address & PCI_MAPREG_TYPE_IO) {
83     printk("pci_mem_find: expected type mem, found I/O\n");
84     return(1);
85  }
86
87  /*
88   * Section 6.2.5.1, `Address Maps', tells us that:
89   *
90   * 1) The builtin software should have already mapped the device in a
91   * reasonable way.
92   *
93   * 2) A device which wants 2^n bytes of memory will hardwire the bottom
94   * n bits of the address to 0.  As recommended, we write all 1s and see
95   * what we get back.
96   */
97  pci_write_config_dword(b,d,f,reg, 0xffffffff);
98  pci_read_config_dword(b,d,f,reg,&mask);
99  pci_write_config_dword(b,d,f,reg, address);
100  if ( (*sizep = PCI_MAPREG_MEM_SIZE(mask))== 0) {
101     printk("pci_io_find: void region\n");
102     return (1);
103  }
104  *basep = PCI_MAPREG_MEM_ADDR(address);
105  return(0);
106}
107
108int pci_get_capability(int b, int d, int f, int capid,int *offset,uint32_t *value)
109{
110  uint32_t reg, ofs;
111
112  /*  i82544EI PCI_CAPLISTPTR_REG */
113  pci_read_config_dword(b,d,f,PCI_CAPLISTPTR_REG, &reg);   
114  ofs = PCI_CAPLIST_PTR(reg);
115  while (ofs != 0) {
116#ifdef DIAGNOSTIC
117    if ((ofs & 3) || (ofs < 0x40))
118       panic("pci_get_capability");
119#endif
120    pci_read_config_dword(b,d,f,ofs, &reg);
121    if (PCI_CAPLIST_CAP(reg) == capid) {
122       if (offset)
123           *offset = ofs;
124       if (value)
125           *value = reg;
126       return (1);
127    }
128    ofs = PCI_CAPLIST_NEXT(reg);
129  }
130  return (0);
131}
Note: See TracBrowser for help on using the repository browser.