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

4.104.114.84.95
Last change on this file since ee732739 was ee732739, checked in by Joel Sherrill <joel.sherrill@…>, on 09/13/07 at 14:26:24

2007-09-07 Kate Feng <feng1@…>

  • ChangeLog?, Makefile.am, README, README.booting, README.irq, preinstall.am, GT64260/MVME5500I2C.c, include/bsp.h, irq/irq.c, irq/irq.h, irq/irq_init.c, pci/detect_host_bridge.c, pci/pci.c, pci/pci_interface.c, pci/pcifinddevice.c, start/preload.S, startup/bspclean.c, startup/bspstart.c, startup/pgtbl_activate.c, startup/reboot.c, vectors/bspException.h, vectors/exceptionhandler.c: Merge my improvements in this BSP including a new network driver for the 1GHz NIC.
  • network/if_100MHz/GT64260eth.c, network/if_100MHz/GT64260eth.h, network/if_100MHz/GT64260ethreg.h, network/if_100MHz/Makefile.am, network/if_1GHz/Makefile.am, network/if_1GHz/POSSIBLEBUG, network/if_1GHz/if_wm.c, network/if_1GHz/if_wmreg.h, network/if_1GHz/pci_map.c, network/if_1GHz/pcireg.h: New files.
  • 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  int s;
70
71  if (reg < PCI_MAPREG_START ||
72#if 0
73            /*
74             * Can't do this check; some devices have mapping registers
75             * way out in left field.
76             */
77            reg >= PCI_MAPREG_END ||
78#endif
79            (reg & 3))
80      rtems_panic("pci_mem_find: bad request");
81
82  pci_read_config_dword(b,d,f,reg, &address);
83  if (address & PCI_MAPREG_TYPE_IO) {
84     printk("pci_mem_find: expected type mem, found I/O\n");
85     return(1);
86  }
87
88  /*
89   * Section 6.2.5.1, `Address Maps', tells us that:
90   *
91   * 1) The builtin software should have already mapped the device in a
92   * reasonable way.
93   *
94   * 2) A device which wants 2^n bytes of memory will hardwire the bottom
95   * n bits of the address to 0.  As recommended, we write all 1s and see
96   * what we get back.
97   */
98  pci_write_config_dword(b,d,f,reg, 0xffffffff);
99  pci_read_config_dword(b,d,f,reg,&mask);
100  pci_write_config_dword(b,d,f,reg, address);
101  if ( (*sizep = PCI_MAPREG_MEM_SIZE(mask))== 0) {
102     printk("pci_io_find: void region\n");
103     return (1);
104  }
105  *basep = PCI_MAPREG_MEM_ADDR(address);
106  return(0);
107}
108
109int pci_get_capability(int b, int d, int f, int capid,int *offset,uint32_t *value)
110{
111  uint32_t reg, ofs;
112
113  /*  i82544EI PCI_CAPLISTPTR_REG */
114  pci_read_config_dword(b,d,f,PCI_CAPLISTPTR_REG, &reg);   
115  ofs = PCI_CAPLIST_PTR(reg);
116  while (ofs != 0) {
117#ifdef DIAGNOSTIC
118    if ((ofs & 3) || (ofs < 0x40))
119       panic("pci_get_capability");
120#endif
121    pci_read_config_dword(b,d,f,ofs, &reg);
122    if (PCI_CAPLIST_CAP(reg) == capid) {
123       if (offset)
124           *offset = ofs;
125       if (value)
126           *value = reg;
127       return (1);
128    }
129    ofs = PCI_CAPLIST_NEXT(reg);
130  }
131  return (0);
132}
Note: See TracBrowser for help on using the repository browser.