pci_machdep.c revision 1.21 1 1.21 dyoung /* $NetBSD: pci_machdep.c,v 1.21 2011/07/01 20:34:53 dyoung Exp $ */
2 1.1 sakamoto
3 1.1 sakamoto /*
4 1.1 sakamoto * Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
5 1.4 mycroft * Copyright (c) 1994 Charles M. Hannum. All rights reserved.
6 1.1 sakamoto *
7 1.1 sakamoto * Redistribution and use in source and binary forms, with or without
8 1.1 sakamoto * modification, are permitted provided that the following conditions
9 1.1 sakamoto * are met:
10 1.1 sakamoto * 1. Redistributions of source code must retain the above copyright
11 1.1 sakamoto * notice, this list of conditions and the following disclaimer.
12 1.1 sakamoto * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 sakamoto * notice, this list of conditions and the following disclaimer in the
14 1.1 sakamoto * documentation and/or other materials provided with the distribution.
15 1.1 sakamoto * 3. All advertising materials mentioning features or use of this software
16 1.1 sakamoto * must display the following acknowledgement:
17 1.4 mycroft * This product includes software developed by Charles M. Hannum.
18 1.1 sakamoto * 4. The name of the author may not be used to endorse or promote products
19 1.1 sakamoto * derived from this software without specific prior written permission.
20 1.1 sakamoto *
21 1.1 sakamoto * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 sakamoto * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 sakamoto * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 sakamoto * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 sakamoto * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 sakamoto * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 sakamoto * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 sakamoto * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 sakamoto * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 sakamoto * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 sakamoto */
32 1.1 sakamoto
33 1.1 sakamoto /*
34 1.1 sakamoto * Machine-specific functions for PCI autoconfiguration.
35 1.1 sakamoto *
36 1.1 sakamoto * On PCs, there are two methods of generating PCI configuration cycles.
37 1.1 sakamoto * We try to detect the appropriate mechanism for this machine and set
38 1.1 sakamoto * up a few function pointers to access the correct method directly.
39 1.1 sakamoto */
40 1.13 lukem
41 1.13 lukem #include <sys/cdefs.h>
42 1.21 dyoung __KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.21 2011/07/01 20:34:53 dyoung Exp $");
43 1.1 sakamoto
44 1.1 sakamoto #include <sys/types.h>
45 1.1 sakamoto #include <sys/param.h>
46 1.1 sakamoto #include <sys/time.h>
47 1.1 sakamoto #include <sys/systm.h>
48 1.1 sakamoto #include <sys/errno.h>
49 1.1 sakamoto #include <sys/device.h>
50 1.1 sakamoto
51 1.7 mrg #include <uvm/uvm_extern.h>
52 1.1 sakamoto
53 1.10 matt #define _POWERPC_BUS_DMA_PRIVATE
54 1.21 dyoung #include <sys/bus.h>
55 1.1 sakamoto #include <machine/intr.h>
56 1.1 sakamoto
57 1.15 garbled #include <powerpc/pio.h>
58 1.15 garbled
59 1.1 sakamoto #include <dev/isa/isavar.h>
60 1.1 sakamoto #include <dev/pci/pcivar.h>
61 1.1 sakamoto #include <dev/pci/pcireg.h>
62 1.15 garbled #include <dev/pci/pcidevs.h>
63 1.1 sakamoto
64 1.15 garbled #include <machine/pci_machdep.h>
65 1.1 sakamoto
66 1.15 garbled extern struct genppc_pci_chipset *genppc_pct;
67 1.1 sakamoto
68 1.15 garbled #define PCI_MODE1_ADDRESS_REG (PREP_BUS_SPACE_IO + 0xcf8)
69 1.15 garbled #define PCI_MODE1_DATA_REG (PREP_BUS_SPACE_IO + 0xcfc)
70 1.1 sakamoto
71 1.1 sakamoto void
72 1.15 garbled bebox_pci_get_chipset_tag(pci_chipset_tag_t pc)
73 1.1 sakamoto {
74 1.15 garbled pc->pc_conf_v = (void *)pc;
75 1.1 sakamoto
76 1.15 garbled pc->pc_attach_hook = genppc_pci_indirect_attach_hook;
77 1.15 garbled pc->pc_bus_maxdevs = genppc_pci_bus_maxdevs;
78 1.15 garbled pc->pc_make_tag = genppc_pci_indirect_make_tag;
79 1.15 garbled pc->pc_conf_read = genppc_pci_indirect_conf_read;
80 1.15 garbled pc->pc_conf_write = genppc_pci_indirect_conf_write;
81 1.15 garbled
82 1.15 garbled pc->pc_intr_v = (void *)pc;
83 1.15 garbled
84 1.15 garbled pc->pc_intr_map = genppc_pci_intr_map;
85 1.15 garbled pc->pc_intr_string = genppc_pci_intr_string;
86 1.15 garbled pc->pc_intr_evcnt = genppc_pci_intr_evcnt;
87 1.15 garbled pc->pc_intr_establish = genppc_pci_intr_establish;
88 1.15 garbled pc->pc_intr_disestablish = genppc_pci_intr_disestablish;
89 1.19 matt pc->pc_intr_setattr = genppc_pci_intr_setattr;
90 1.15 garbled
91 1.15 garbled pc->pc_conf_interrupt = bebox_pci_conf_interrupt;
92 1.15 garbled pc->pc_decompose_tag = genppc_pci_indirect_decompose_tag;
93 1.15 garbled pc->pc_conf_hook = genppc_pci_conf_hook;
94 1.15 garbled
95 1.20 matt pc->pc_addr = mapiodev(PCI_MODE1_ADDRESS_REG, 4, false);
96 1.20 matt pc->pc_data = mapiodev(PCI_MODE1_DATA_REG, 4, false);
97 1.15 garbled pc->pc_bus = 0;
98 1.15 garbled pc->pc_node = 0;
99 1.15 garbled pc->pc_memt = 0;
100 1.15 garbled pc->pc_iot = 0;
101 1.9 briggs }
102 1.9 briggs
103 1.9 briggs void
104 1.19 matt bebox_pci_conf_interrupt(void *v, int bus, int dev, int pin, int swiz,
105 1.19 matt int *iline)
106 1.9 briggs {
107 1.16 kiyohara
108 1.16 kiyohara if (bus == 0) {
109 1.16 kiyohara switch (dev) {
110 1.16 kiyohara case 12: /* SCSI is bit 10, mapped to IRQ 26 */
111 1.16 kiyohara case 13: /* PCI slot 1 is bit 11, mapped to IRQ 27 */
112 1.16 kiyohara case 14: /* PCI slot 2 is bit 12, mapped to IRQ 28 */
113 1.16 kiyohara case 15: /* PCI slot 3 is bit 13, mapped to IRQ 29 */
114 1.16 kiyohara #define BEBOX_PCIBUS0_DEV2LINE(d) ((d) + 14)
115 1.16 kiyohara *iline = BEBOX_PCIBUS0_DEV2LINE(dev);
116 1.16 kiyohara }
117 1.16 kiyohara } else
118 1.18 kiyohara #define BEBOX_PCIBUS_SWIZ2LINE(s) ((s) + 14)
119 1.18 kiyohara *iline = BEBOX_PCIBUS_SWIZ2LINE(swiz);
120 1.1 sakamoto }
121