pciconf_indirect.c revision 1.1.2.2 1 1.1.2.2 macallan /* $NetBSD: pciconf_indirect.c,v 1.1.2.2 2007/05/06 05:11:42 macallan Exp $ */
2 1.1.2.1 garbled
3 1.1.2.1 garbled /*-
4 1.1.2.1 garbled * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 1.1.2.1 garbled * All rights reserved.
6 1.1.2.1 garbled *
7 1.1.2.1 garbled * This code is derived from software contributed to The NetBSD Foundation
8 1.1.2.1 garbled * by Tim Rightnour
9 1.1.2.1 garbled *
10 1.1.2.1 garbled * Redistribution and use in source and binary forms, with or without
11 1.1.2.1 garbled * modification, are permitted provided that the following conditions
12 1.1.2.1 garbled * are met:
13 1.1.2.1 garbled * 1. Redistributions of source code must retain the above copyright
14 1.1.2.1 garbled * notice, this list of conditions and the following disclaimer.
15 1.1.2.1 garbled * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.2.1 garbled * notice, this list of conditions and the following disclaimer in the
17 1.1.2.1 garbled * documentation and/or other materials provided with the distribution.
18 1.1.2.1 garbled * 3. All advertising materials mentioning features or use of this software
19 1.1.2.1 garbled * must display the following acknowledgement:
20 1.1.2.1 garbled * This product includes software developed by the NetBSD
21 1.1.2.1 garbled * Foundation, Inc. and its contributors.
22 1.1.2.1 garbled * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.2.1 garbled * contributors may be used to endorse or promote products derived
24 1.1.2.1 garbled * from this software without specific prior written permission.
25 1.1.2.1 garbled *
26 1.1.2.1 garbled * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.2.1 garbled * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.2.1 garbled * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.2.1 garbled * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.2.1 garbled * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.2.1 garbled * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.2.1 garbled * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.2.1 garbled * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.2.1 garbled * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.2.1 garbled * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.2.1 garbled * POSSIBILITY OF SUCH DAMAGE.
37 1.1.2.1 garbled */
38 1.1.2.1 garbled
39 1.1.2.1 garbled /*
40 1.1.2.1 garbled * Generic PowerPC functions for talking to an indirect configuration style
41 1.1.2.1 garbled * PCI Bridge.
42 1.1.2.1 garbled */
43 1.1.2.1 garbled
44 1.1.2.1 garbled #include <sys/cdefs.h>
45 1.1.2.2 macallan __KERNEL_RCSID(0, "$NetBSD: pciconf_indirect.c,v 1.1.2.2 2007/05/06 05:11:42 macallan Exp $");
46 1.1.2.1 garbled
47 1.1.2.1 garbled #include <sys/types.h>
48 1.1.2.1 garbled #include <sys/param.h>
49 1.1.2.1 garbled #include <sys/time.h>
50 1.1.2.1 garbled #include <sys/systm.h>
51 1.1.2.1 garbled #include <sys/errno.h>
52 1.1.2.1 garbled #include <sys/device.h>
53 1.1.2.1 garbled
54 1.1.2.1 garbled #include <uvm/uvm_extern.h>
55 1.1.2.1 garbled
56 1.1.2.1 garbled #define _POWERPC_BUS_DMA_PRIVATE
57 1.1.2.1 garbled #include <machine/bus.h>
58 1.1.2.1 garbled #include <machine/intr.h>
59 1.1.2.1 garbled #include <machine/pio.h>
60 1.1.2.2 macallan #ifdef prep
61 1.1.2.1 garbled #include <machine/platform.h>
62 1.1.2.2 macallan #endif
63 1.1.2.1 garbled
64 1.1.2.2 macallan #if NISA > 0
65 1.1.2.1 garbled #include <dev/isa/isavar.h>
66 1.1.2.2 macallan #endif
67 1.1.2.2 macallan
68 1.1.2.1 garbled #include <dev/pci/pcivar.h>
69 1.1.2.1 garbled #include <dev/pci/pcireg.h>
70 1.1.2.1 garbled #include <dev/pci/pcidevs.h>
71 1.1.2.1 garbled
72 1.1.2.1 garbled #define PCI_MODE1_ENABLE 0x80000000UL
73 1.1.2.1 garbled
74 1.1.2.1 garbled void genppc_pci_indirect_attach_hook(struct device *, struct device *,
75 1.1.2.1 garbled struct pcibus_attach_args *);
76 1.1.2.1 garbled pcitag_t genppc_pci_indirect_make_tag(void *, int, int, int);
77 1.1.2.1 garbled pcireg_t genppc_pci_indirect_conf_read(void *, pcitag_t, int);
78 1.1.2.1 garbled void genppc_pci_indirect_conf_write(void *, pcitag_t, int, pcireg_t);
79 1.1.2.1 garbled void genppc_pci_indirect_decompose_tag(void *, pcitag_t, int *, int *, int *);
80 1.1.2.1 garbled
81 1.1.2.1 garbled void
82 1.1.2.1 garbled genppc_pci_indirect_attach_hook(struct device *parent, struct device *self,
83 1.1.2.1 garbled struct pcibus_attach_args *pba)
84 1.1.2.1 garbled {
85 1.1.2.1 garbled
86 1.1.2.1 garbled if (pba->pba_bus != 0)
87 1.1.2.1 garbled return;
88 1.1.2.1 garbled
89 1.1.2.1 garbled printf(": indirect configuration space access");
90 1.1.2.1 garbled }
91 1.1.2.1 garbled
92 1.1.2.1 garbled pcitag_t
93 1.1.2.1 garbled genppc_pci_indirect_make_tag(void *v, int bus, int device, int function)
94 1.1.2.1 garbled {
95 1.1.2.1 garbled pcitag_t tag;
96 1.1.2.1 garbled
97 1.1.2.1 garbled if (bus >= 256 || device >= 32 || function >= 8)
98 1.1.2.1 garbled panic("pci_make_tag: bad request");
99 1.1.2.1 garbled
100 1.1.2.1 garbled tag = PCI_MODE1_ENABLE |
101 1.1.2.1 garbled (bus << 16) | (device << 11) | (function << 8);
102 1.1.2.1 garbled return tag;
103 1.1.2.1 garbled }
104 1.1.2.1 garbled
105 1.1.2.1 garbled void
106 1.1.2.1 garbled genppc_pci_indirect_decompose_tag(void *v, pcitag_t tag, int *bp, int *dp,
107 1.1.2.1 garbled int *fp)
108 1.1.2.1 garbled {
109 1.1.2.1 garbled
110 1.1.2.1 garbled if (bp != NULL)
111 1.1.2.1 garbled *bp = (tag >> 16) & 0xff;
112 1.1.2.1 garbled if (dp != NULL)
113 1.1.2.1 garbled *dp = (tag >> 11) & 0x1f;
114 1.1.2.1 garbled if (fp != NULL)
115 1.1.2.1 garbled *fp = (tag >> 8) & 0x7;
116 1.1.2.1 garbled return;
117 1.1.2.1 garbled }
118 1.1.2.1 garbled
119 1.1.2.1 garbled pcireg_t
120 1.1.2.1 garbled genppc_pci_indirect_conf_read(void *v, pcitag_t tag, int reg)
121 1.1.2.1 garbled {
122 1.1.2.1 garbled pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
123 1.1.2.1 garbled pcireg_t data;
124 1.1.2.1 garbled int s;
125 1.1.2.1 garbled
126 1.1.2.1 garbled s = splhigh();
127 1.1.2.1 garbled out32rb(pc->pc_addr, tag | reg);
128 1.1.2.1 garbled data = in32rb(pc->pc_data);
129 1.1.2.1 garbled out32rb(pc->pc_addr, 0);
130 1.1.2.1 garbled splx(s);
131 1.1.2.1 garbled
132 1.1.2.1 garbled return data;
133 1.1.2.1 garbled }
134 1.1.2.1 garbled
135 1.1.2.1 garbled void
136 1.1.2.1 garbled genppc_pci_indirect_conf_write(void *v, pcitag_t tag, int reg, pcireg_t data)
137 1.1.2.1 garbled {
138 1.1.2.1 garbled pci_chipset_tag_t pc = (pci_chipset_tag_t)v;
139 1.1.2.1 garbled int s;
140 1.1.2.1 garbled
141 1.1.2.1 garbled s = splhigh();
142 1.1.2.1 garbled out32rb(pc->pc_addr, tag | reg);
143 1.1.2.1 garbled out32rb(pc->pc_data, data);
144 1.1.2.1 garbled out32rb(pc->pc_addr, 0);
145 1.1.2.1 garbled splx(s);
146 1.1.2.1 garbled }
147