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