1 /* $NetBSD: lca_pci.c,v 1.17 2009/03/14 15:35:59 dsl Exp $ */
4 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
7 * Author: Chris G. Demetriou
9 * Permission to use, copy, modify and distribute this software and
10 * its documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19 * Carnegie Mellon requests users of this software to return to
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
30 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
32 __KERNEL_RCSID(0, "$NetBSD: lca_pci.c,v 1.17 2009/03/14 15:35:59 dsl Exp $");
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/device.h>
39 #include <uvm/uvm_extern.h>
41 #include <dev/pci/pcireg.h>
42 #include <dev/pci/pcivar.h>
43 #include <alpha/pci/lcareg.h>
44 #include <alpha/pci/lcavar.h>
46 void lca_attach_hook(struct device
*, struct device
*,
47 struct pcibus_attach_args
*);
48 int lca_bus_maxdevs(void *, int);
49 pcitag_t
lca_make_tag(void *, int, int, int);
50 void lca_decompose_tag(void *, pcitag_t
, int *, int *,
52 pcireg_t
lca_conf_read(void *, pcitag_t
, int);
53 void lca_conf_write(void *, pcitag_t
, int, pcireg_t
);
56 lca_pci_init(pci_chipset_tag_t pc
, void *v
)
60 pc
->pc_attach_hook
= lca_attach_hook
;
61 pc
->pc_bus_maxdevs
= lca_bus_maxdevs
;
62 pc
->pc_make_tag
= lca_make_tag
;
63 pc
->pc_decompose_tag
= lca_decompose_tag
;
64 pc
->pc_conf_read
= lca_conf_read
;
65 pc
->pc_conf_write
= lca_conf_write
;
69 lca_attach_hook(struct device
*parent
, struct device
*self
, struct pcibus_attach_args
*pba
)
74 lca_bus_maxdevs(void *cpv
, int busno
)
84 lca_make_tag(void *cpv
, int b
, int d
, int f
)
87 return (b
<< 16) | (d
<< 11) | (f
<< 8);
91 lca_decompose_tag(void *cpv
, pcitag_t tag
, int *bp
, int *dp
, int *fp
)
95 *bp
= (tag
>> 16) & 0xff;
97 *dp
= (tag
>> 11) & 0x1f;
99 *fp
= (tag
>> 8) & 0x7;
103 lca_conf_read(void *cpv
, pcitag_t tag
, int offset
)
105 struct lca_config
*lcp
= cpv
;
106 pcireg_t
*datap
, data
;
107 int s
, secondary
, device
, ba
;
109 s
= 0; /* XXX gcc -Wuninitialized */
111 /* secondary if bus # != 0 */
112 pci_decompose_tag(&lcp
->lc_pc
, tag
, &secondary
, &device
, 0);
116 REGVAL(LCA_IOC_CONF
) = 0x01;
120 * on the LCA, must frob the tag used for
121 * devices on the primary bus, in the same ways
122 * as is used by type 1 configuration cycles
125 tag
= (1 << (device
+ 11)) | (tag
& 0x7ff);
128 datap
= (pcireg_t
*)ALPHA_PHYS_TO_K0SEG(LCA_PCI_CONF
|
129 tag
<< 5UL | /* XXX */
130 (offset
& ~0x03) << 5 | /* XXX */
134 if (!(ba
= badaddr(datap
, sizeof *datap
)))
139 REGVAL(LCA_IOC_CONF
) = 0x00;
145 printf("lca_conf_read: tag 0x%lx, reg 0x%lx -> %x @ %p%s\n", tag
, reg
,
146 data
, datap
, ba
? " (badaddr)" : "");
153 lca_conf_write(void *cpv
, pcitag_t tag
, int offset
, pcireg_t data
)
155 struct lca_config
*lcp
= cpv
;
157 int s
, secondary
, device
;
159 s
= 0; /* XXX gcc -Wuninitialized */
161 /* secondary if bus # != 0 */
162 pci_decompose_tag(&lcp
->lc_pc
, tag
, &secondary
, &device
, 0);
166 REGVAL(LCA_IOC_CONF
) = 0x01;
170 * on the LCA, must frob the tag used for
171 * devices on the primary bus, in the same ways
172 * as is used by type 1 configuration cycles
175 tag
= (1 << (device
+ 11)) | (tag
& 0x7ff);
178 datap
= (pcireg_t
*)ALPHA_PHYS_TO_K0SEG(LCA_PCI_CONF
|
179 tag
<< 5UL | /* XXX */
180 (offset
& ~0x03) << 5 | /* XXX */
187 REGVAL(LCA_IOC_CONF
) = 0x00;
193 printf("lca_conf_write: tag 0x%lx, reg 0x%lx -> 0x%x @ %p\n", tag
,