1/*	$NetBSD: pci_machdep.c,v 1.21 2011/05/11 17:49:31 dyoung Exp $	*/
2
3/*
4 * Copyright (c) 2000 Soren S. Jorvang
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 *    must display the following acknowledgement:
17 *          This product includes software developed for the
18 *          NetBSD Project.  See http://www.NetBSD.org/ for
19 *          information about NetBSD.
20 * 4. The name of the author may not be used to endorse or promote products
21 *    derived from this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#include <sys/cdefs.h>
36__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.21 2011/05/11 17:49:31 dyoung Exp $");
37
38#include "opt_pci.h"
39#include "pci.h"
40
41#include <sys/types.h>
42#include <sys/param.h>
43#include <sys/time.h>
44#include <sys/systm.h>
45#include <sys/errno.h>
46#include <sys/device.h>
47
48#include <uvm/uvm_extern.h>
49
50#define _SGIMIPS_BUS_DMA_PRIVATE
51#include <sys/bus.h>
52#include <machine/intr.h>
53#include <machine/sysconf.h>
54
55#include <dev/pci/pcivar.h>
56#include <dev/pci/pcireg.h>
57#include <dev/pci/pcidevs.h>
58#include <dev/pci/pciconf.h>
59
60struct sgimips_bus_dma_tag pci_bus_dma_tag;
61
62void
63pci_attach_hook(struct device *parent, struct device *self, struct pcibus_attach_args *pba)
64{
65	/*
66	 * PCI doesn't have any special needs; just use
67	 * the generic versions of these functions as
68	 * established in sgimips_bus_dma_init().
69	 */
70	pci_bus_dma_tag = sgimips_default_bus_dma_tag;	/* struct copy */
71
72	/* XXX */
73
74	return;
75}
76
77int
78pci_bus_maxdevs(pci_chipset_tag_t pc, int busno)
79{
80
81	return (*pc->pc_bus_maxdevs)(pc, busno);
82}
83
84pcitag_t
85pci_make_tag(pci_chipset_tag_t pc, int bus, int device, int function)
86{
87
88	return (bus << 16) | (device << 11) | (function << 8);
89}
90
91void
92pci_decompose_tag(pci_chipset_tag_t pc, pcitag_t tag, int *bp, int *dp, int *fp)
93{
94
95	if (bp != NULL)
96		*bp = (tag >> 16) & 0xff;
97	if (dp != NULL)
98		*dp = (tag >> 11) & 0x1f;
99	if (fp != NULL)
100		*fp = (tag >> 8) & 0x07;
101}
102
103pcireg_t
104pci_conf_read(pci_chipset_tag_t pc, pcitag_t tag, int reg)
105{
106
107	return (*pc->pc_conf_read)(pc, tag, reg);
108}
109
110void
111pci_conf_write(pci_chipset_tag_t pc, pcitag_t tag, int reg, pcireg_t data)
112{
113
114	(*pc->pc_conf_write)(pc, tag, reg, data);
115}
116
117int
118pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
119{
120	return (*pa->pa_pc->pc_intr_map)(pa, ihp);
121}
122
123const char *
124pci_intr_string(pci_chipset_tag_t pc, pci_intr_handle_t ih)
125{
126	return (*pc->pc_intr_string)(pc, ih);
127}
128
129const struct evcnt *
130pci_intr_evcnt(pci_chipset_tag_t pc, pci_intr_handle_t ih)
131{
132
133	/* XXX for now, no evcnt parent reported */
134	return NULL;
135}
136
137int
138pci_intr_setattr(pci_chipset_tag_t pc, pci_intr_handle_t *ih,
139		 int attr, uint64_t data)
140{
141
142	switch (attr) {
143	case PCI_INTR_MPSAFE:
144		return 0;
145	default:
146		return ENODEV;
147	}
148}
149
150void *
151pci_intr_establish(pci_chipset_tag_t pc, pci_intr_handle_t ih, int level,
152	int (*func)(void *), void *arg)
153{
154
155	return (void *)(*pc->intr_establish)(ih, 0, func, arg);
156}
157
158void
159pci_intr_disestablish(pci_chipset_tag_t pc, void *cookie)
160{
161
162	(*pc->intr_disestablish)(cookie);
163}
164
165#ifdef PCI_NETBSD_CONFIGURE
166int
167pci_conf_hook(pci_chipset_tag_t pc, int bus, int device, int function,
168    pcireg_t id)
169{
170
171	if (pc->pc_conf_hook)
172		return (*pc->pc_conf_hook)(pc, bus, device, function, id);
173	else
174		return (PCI_CONF_DEFAULT);
175}
176
177void
178pci_conf_interrupt(pci_chipset_tag_t pc, int bus, int dev, int pin, int swiz,
179    int *iline)
180{
181
182	return;
183}
184#endif
185