1*aec6f0cfSskrll /* $NetBSD: admpci.c,v 1.18 2022/09/29 07:00:46 skrll Exp $ */
2320845ddSdyoung
3320845ddSdyoung /*-
4320845ddSdyoung * Copyright (c) 2007 David Young. All rights reserved.
5320845ddSdyoung *
6320845ddSdyoung * Redistribution and use in source and binary forms, with or
7320845ddSdyoung * without modification, are permitted provided that the following
8320845ddSdyoung * conditions are met:
9320845ddSdyoung * 1. Redistributions of source code must retain the above copyright
10320845ddSdyoung * notice, this list of conditions and the following disclaimer.
11320845ddSdyoung * 2. Redistributions in binary form must reproduce the above
12320845ddSdyoung * copyright notice, this list of conditions and the following
13320845ddSdyoung * disclaimer in the documentation and/or other materials provided
14320845ddSdyoung * with the distribution.
15320845ddSdyoung *
16320845ddSdyoung * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY
17320845ddSdyoung * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18320845ddSdyoung * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19320845ddSdyoung * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR
20320845ddSdyoung * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
21320845ddSdyoung * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22320845ddSdyoung * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
23320845ddSdyoung * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24320845ddSdyoung * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
25320845ddSdyoung * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26320845ddSdyoung * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
27320845ddSdyoung * OF SUCH DAMAGE.
28320845ddSdyoung */
29320845ddSdyoung /*-
30320845ddSdyoung * Copyright (c) 2006 Itronix Inc.
31320845ddSdyoung * All rights reserved.
32320845ddSdyoung *
33320845ddSdyoung * Written by Garrett D'Amore for Itronix Inc.
34320845ddSdyoung *
35320845ddSdyoung * Redistribution and use in source and binary forms, with or without
36320845ddSdyoung * modification, are permitted provided that the following conditions
37320845ddSdyoung * are met:
38320845ddSdyoung * 1. Redistributions of source code must retain the above copyright
39320845ddSdyoung * notice, this list of conditions and the following disclaimer.
40320845ddSdyoung * 2. Redistributions in binary form must reproduce the above copyright
41320845ddSdyoung * notice, this list of conditions and the following disclaimer in the
42320845ddSdyoung * documentation and/or other materials provided with the distribution.
43320845ddSdyoung * 3. The name of Itronix Inc. may not be used to endorse
44320845ddSdyoung * or promote products derived from this software without specific
45320845ddSdyoung * prior written permission.
46320845ddSdyoung *
47320845ddSdyoung * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
48320845ddSdyoung * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
49320845ddSdyoung * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
50320845ddSdyoung * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
51320845ddSdyoung * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
52320845ddSdyoung * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
53320845ddSdyoung * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
54320845ddSdyoung * ON ANY THEORY OF LIABILITY, WHETHER IN
55320845ddSdyoung * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
56320845ddSdyoung * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
57320845ddSdyoung * POSSIBILITY OF SUCH DAMAGE.
58320845ddSdyoung */
59320845ddSdyoung
60320845ddSdyoung #include "opt_pci.h"
61320845ddSdyoung #include "pci.h"
62320845ddSdyoung
63320845ddSdyoung #include <sys/cdefs.h>
64*aec6f0cfSskrll __KERNEL_RCSID(0, "$NetBSD: admpci.c,v 1.18 2022/09/29 07:00:46 skrll Exp $");
65320845ddSdyoung
6622209f79Smatt #include <sys/param.h>
67320845ddSdyoung #include <sys/types.h>
68b6185cbdSmatt #include <sys/bus.h>
69b6185cbdSmatt #include <sys/cpu.h>
70320845ddSdyoung #include <sys/time.h>
71320845ddSdyoung #include <sys/systm.h>
72320845ddSdyoung #include <sys/errno.h>
73320845ddSdyoung #include <sys/device.h>
74320845ddSdyoung #include <sys/extent.h>
75320845ddSdyoung
76320845ddSdyoung #include <uvm/uvm_extern.h>
77320845ddSdyoung
78320845ddSdyoung #include <dev/pci/pcivar.h>
79320845ddSdyoung #include <dev/pci/pcireg.h>
80320845ddSdyoung #include <dev/pci/pciconf.h>
81320845ddSdyoung
82320845ddSdyoung #ifdef PCI_NETBSD_CONFIGURE
83320845ddSdyoung #include <mips/cache.h>
84320845ddSdyoung #endif
85320845ddSdyoung
86320845ddSdyoung #include <mips/adm5120/include/adm5120_mainbusvar.h>
87320845ddSdyoung #include <mips/adm5120/include/adm5120reg.h>
88320845ddSdyoung #include <mips/adm5120/include/adm5120var.h>
89320845ddSdyoung
90320845ddSdyoung #ifdef ADMPCI_DEBUG
91320845ddSdyoung int admpci_debug = 1;
92320845ddSdyoung #define ADMPCI_DPRINTF(__fmt, ...) \
93320845ddSdyoung do { \
94320845ddSdyoung if (admpci_debug) \
95320845ddSdyoung printf((__fmt), __VA_ARGS__); \
96320845ddSdyoung } while (/*CONSTCOND*/0)
97320845ddSdyoung #else /* !ADMPCI_DEBUG */
98320845ddSdyoung #define ADMPCI_DPRINTF(__fmt, ...) do { } while (/*CONSTCOND*/0)
99320845ddSdyoung #endif /* ADMPCI_DEBUG */
100320845ddSdyoung
101320845ddSdyoung #define ADMPCI_TAG_BUS_MASK __BITS(23, 16)
102320845ddSdyoung /* Bit 11 is reserved. It selects the AHB-PCI bridge. Let device 0
103320845ddSdyoung * be the bridge. For all other device numbers, let bit[11] == 0.
104320845ddSdyoung */
105320845ddSdyoung #define ADMPCI_TAG_DEVICE_MASK __BITS(15, 11)
106320845ddSdyoung #define ADMPCI_TAG_DEVICE_SUBMASK __BITS(15, 12)
107320845ddSdyoung #define ADMPCI_TAG_DEVICE_BRIDGE __BIT(11)
108320845ddSdyoung #define ADMPCI_TAG_FUNCTION_MASK __BITS(10, 8)
109320845ddSdyoung #define ADMPCI_TAG_REGISTER_MASK __BITS(7, 0)
110320845ddSdyoung
111320845ddSdyoung #define ADMPCI_MAX_DEVICE
112320845ddSdyoung
113320845ddSdyoung struct admpci_softc {
114b6185cbdSmatt device_t sc_dev;
115320845ddSdyoung struct mips_pci_chipset sc_pc;
116320845ddSdyoung
117320845ddSdyoung bus_space_tag_t sc_memt;
118320845ddSdyoung bus_space_tag_t sc_iot;
119320845ddSdyoung
120320845ddSdyoung bus_space_tag_t sc_conft;
121320845ddSdyoung bus_space_handle_t sc_addrh;
122320845ddSdyoung bus_space_handle_t sc_datah;
123320845ddSdyoung };
124320845ddSdyoung
125b6185cbdSmatt int admpcimatch(device_t, cfdata_t, void *);
126b6185cbdSmatt void admpciattach(device_t, device_t, void *);
127320845ddSdyoung
128320845ddSdyoung #if NPCI > 0
129b6185cbdSmatt static void admpci_attach_hook(device_t, device_t,
130320845ddSdyoung struct pcibus_attach_args *);
131320845ddSdyoung static int admpci_bus_maxdevs(void *, int);
132320845ddSdyoung static pcitag_t admpci_make_tag(void *, int, int, int);
133320845ddSdyoung static void admpci_decompose_tag(void *, pcitag_t, int *, int *, int *);
134320845ddSdyoung static pcireg_t admpci_conf_read(void *, pcitag_t, int);
135320845ddSdyoung static void admpci_conf_write(void *, pcitag_t, int, pcireg_t);
136e58a356cSchristos static const char *admpci_intr_string(void *, pci_intr_handle_t, char *, size_t);
137320845ddSdyoung static void admpci_conf_interrupt(void *, int, int, int, int, int *);
138320845ddSdyoung static void *admpci_intr_establish(void *, pci_intr_handle_t, int,
139320845ddSdyoung int (*)(void *), void *);
140320845ddSdyoung static void admpci_intr_disestablish(void *, void *);
141d3e53912Sdyoung static int admpci_intr_map(const struct pci_attach_args *, pci_intr_handle_t *);
142320845ddSdyoung #endif /* NPCI > 0 */
143320845ddSdyoung
144b6185cbdSmatt CFATTACH_DECL_NEW(admpci, sizeof(struct admpci_softc),
145320845ddSdyoung admpcimatch, admpciattach, NULL, NULL);
146320845ddSdyoung
147320845ddSdyoung int admpci_found = 0;
148320845ddSdyoung
149320845ddSdyoung /*
150320845ddSdyoung * Physical PCI addresses are 36-bits long, so we need to have
151320845ddSdyoung * adequate storage space for them.
152320845ddSdyoung */
153320845ddSdyoung #if NPCI > 0
154320845ddSdyoung #if !defined(_MIPS_PADDR_T_64BIT) && !defined(_LP64)
155320845ddSdyoung #error "admpci requires 64 bit paddr_t!"
156320845ddSdyoung #endif
157320845ddSdyoung #endif
158320845ddSdyoung
159ca8ce3aeSthorpej #define PCI_IO_START ADM5120_BASE_PCI_IO
160ca8ce3aeSthorpej #define PCI_IO_SIZE (ADM5120_BASE_PCI_CONFADDR - ADM5120_BASE_PCI_IO)
161ca8ce3aeSthorpej
162ca8ce3aeSthorpej #define PCI_MEM_START1 ADM5120_BASE_PCI_MEM
163ca8ce3aeSthorpej #define PCI_MEM_SIZE1 (ADM5120_BASE_PCI_IO - ADM5120_BASE_PCI_MEM)
164ca8ce3aeSthorpej
165ca8ce3aeSthorpej #define PCI_MEM_START2 ADM5120_BOTTOM
166ca8ce3aeSthorpej #define PCI_MEM_SIZE2 (ADM5120_BASE_SRAM1 - ADM5120_BOTTOM)
167ca8ce3aeSthorpej
168320845ddSdyoung int
admpcimatch(device_t parent,cfdata_t match,void * aux)169b6185cbdSmatt admpcimatch(device_t parent, cfdata_t match, void *aux)
170320845ddSdyoung {
171320845ddSdyoung struct mainbus_attach_args *ma = (struct mainbus_attach_args *)aux;
172320845ddSdyoung
173320845ddSdyoung return !admpci_found && strcmp(ma->ma_name, "admpci") == 0;
174320845ddSdyoung }
175320845ddSdyoung
176320845ddSdyoung void
admpciattach(device_t parent,device_t self,void * aux)177b6185cbdSmatt admpciattach(device_t parent, device_t self, void *aux)
178320845ddSdyoung {
179320845ddSdyoung struct adm5120_config *admc = &adm5120_configuration;
180b6185cbdSmatt struct admpci_softc *sc = device_private(self);
181320845ddSdyoung struct mainbus_attach_args *ma = (struct mainbus_attach_args *)aux;
182320845ddSdyoung #if NPCI > 0
183320845ddSdyoung struct pcibus_attach_args pba;
184320845ddSdyoung #endif
185320845ddSdyoung
186320845ddSdyoung admpci_found = 1;
187320845ddSdyoung
188b6185cbdSmatt sc->sc_dev = self;
189320845ddSdyoung sc->sc_conft = ma->ma_obiot;
190320845ddSdyoung if (bus_space_map(sc->sc_conft, ADM5120_BASE_PCI_CONFDATA, 4, 0,
191320845ddSdyoung &sc->sc_datah) != 0) {
192b6185cbdSmatt aprint_error(
193b6185cbdSmatt ": unable to map PCI Configuration Data register\n");
194320845ddSdyoung return;
195320845ddSdyoung }
196320845ddSdyoung if (bus_space_map(sc->sc_conft, ADM5120_BASE_PCI_CONFADDR, 4, 0,
197320845ddSdyoung &sc->sc_addrh) != 0) {
198b6185cbdSmatt aprint_error(
199b6185cbdSmatt ": unable to map PCI Configuration Address register\n");
200320845ddSdyoung return;
201320845ddSdyoung }
202320845ddSdyoung
203b6185cbdSmatt aprint_normal(": ADM5120 Host-PCI Bridge, "
204b6185cbdSmatt "data %"PRIxBSH" addr %"PRIxBSH", sc %p\n",
205b6185cbdSmatt sc->sc_datah, sc->sc_addrh, sc);
206320845ddSdyoung
207320845ddSdyoung #if NPCI > 0
208320845ddSdyoung sc->sc_memt = &admc->pcimem_space;
209320845ddSdyoung sc->sc_iot = &admc->pciio_space;
210320845ddSdyoung
211320845ddSdyoung sc->sc_pc.pc_conf_v = sc;
212320845ddSdyoung sc->sc_pc.pc_attach_hook = admpci_attach_hook;
213320845ddSdyoung sc->sc_pc.pc_bus_maxdevs = admpci_bus_maxdevs;
214320845ddSdyoung sc->sc_pc.pc_make_tag = admpci_make_tag;
215320845ddSdyoung sc->sc_pc.pc_decompose_tag = admpci_decompose_tag;
216320845ddSdyoung sc->sc_pc.pc_conf_read = admpci_conf_read;
217320845ddSdyoung sc->sc_pc.pc_conf_write = admpci_conf_write;
218320845ddSdyoung
219320845ddSdyoung sc->sc_pc.pc_intr_v = sc;
220320845ddSdyoung sc->sc_pc.pc_intr_map = admpci_intr_map;
221320845ddSdyoung sc->sc_pc.pc_intr_string = admpci_intr_string;
222320845ddSdyoung sc->sc_pc.pc_intr_establish = admpci_intr_establish;
223320845ddSdyoung sc->sc_pc.pc_intr_disestablish = admpci_intr_disestablish;
224320845ddSdyoung sc->sc_pc.pc_conf_interrupt = admpci_conf_interrupt;
225320845ddSdyoung
22670a57c80Sskrll #ifdef ADMPCI_DEBUG
22770a57c80Sskrll pcitag_t tag = pci_make_tag(&sc->sc_pc, 0, 0, 0);
228320845ddSdyoung ADMPCI_DPRINTF("%s: BAR 0x10 0x%08x\n", __func__,
229320845ddSdyoung pci_conf_read(&sc->sc_pc, tag, PCI_MAPREG_START));
23070a57c80Sskrll #endif
231320845ddSdyoung
232320845ddSdyoung #ifdef PCI_NETBSD_CONFIGURE
233ca8ce3aeSthorpej struct pciconf_resources *pcires = pciconf_resource_init();
234320845ddSdyoung
235ca8ce3aeSthorpej pciconf_resource_add(pcires, PCICONF_RESOURCE_IO,
236ca8ce3aeSthorpej PCI_IO_START, PCI_IO_SIZE);
237ca8ce3aeSthorpej pciconf_resource_add(pcires, PCICONF_RESOURCE_MEM,
238ca8ce3aeSthorpej PCI_MEM_START1, PCI_MEM_SIZE1);
239320845ddSdyoung
240ca8ce3aeSthorpej /* XXX Is this one really needed? */
241ca8ce3aeSthorpej pciconf_resource_add(pcires, PCICONF_RESOURCE_MEM,
242ca8ce3aeSthorpej PCI_MEM_START2, PCI_MEM_SIZE2);
243ca8ce3aeSthorpej
244ca8ce3aeSthorpej pci_configure_bus(&sc->sc_pc, pcires,
245ca8ce3aeSthorpej 0, mips_cache_info.mci_dcache_align);
246ca8ce3aeSthorpej
247ca8ce3aeSthorpej pciconf_resource_fini(pcires);
248320845ddSdyoung #endif
249320845ddSdyoung
250320845ddSdyoung pba.pba_iot = sc->sc_iot;
251320845ddSdyoung pba.pba_memt = sc->sc_memt;
252320845ddSdyoung /* XXX: review dma tag logic */
253320845ddSdyoung pba.pba_dmat = ma->ma_dmat;
254320845ddSdyoung pba.pba_dmat64 = NULL;
255320845ddSdyoung pba.pba_pc = &sc->sc_pc;
256a6b2b839Sdyoung pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY;
257320845ddSdyoung pba.pba_bus = 0;
258320845ddSdyoung pba.pba_bridgetag = NULL;
259320845ddSdyoung
2602685996bSthorpej config_found(self, &pba, pcibusprint,
261c7fb772bSthorpej CFARGS(.iattr = "pcibus"));
262320845ddSdyoung #endif /* NPCI > 0 */
263320845ddSdyoung }
264320845ddSdyoung
265320845ddSdyoung #if NPCI > 0
266320845ddSdyoung
267320845ddSdyoung void
admpci_attach_hook(device_t parent,device_t self,struct pcibus_attach_args * pba)268b6185cbdSmatt admpci_attach_hook(device_t parent, device_t self,
269320845ddSdyoung struct pcibus_attach_args *pba)
270320845ddSdyoung {
271320845ddSdyoung }
272320845ddSdyoung
273320845ddSdyoung /* There are at most four devices on bus 0. The ADM5120 has
274320845ddSdyoung * request/grant lines for 3 PCI devices: 1, 2, and 3. The host
275320845ddSdyoung * bridge is device 0.
276320845ddSdyoung */
277320845ddSdyoung int
admpci_bus_maxdevs(void * v,int bus)278320845ddSdyoung admpci_bus_maxdevs(void *v, int bus)
279320845ddSdyoung {
280320845ddSdyoung if (bus == 0)
281320845ddSdyoung return 4;
282320845ddSdyoung
283320845ddSdyoung return 1 + __SHIFTOUT_MASK(ADMPCI_TAG_DEVICE_MASK);
284320845ddSdyoung }
285320845ddSdyoung
286320845ddSdyoung pcitag_t
admpci_make_tag(void * v,int bus,int device,int function)287320845ddSdyoung admpci_make_tag(void *v, int bus, int device, int function)
288320845ddSdyoung {
289320845ddSdyoung if (bus > __SHIFTOUT_MASK(ADMPCI_TAG_BUS_MASK) ||
290320845ddSdyoung device > __SHIFTOUT_MASK(ADMPCI_TAG_DEVICE_MASK) ||
291320845ddSdyoung function > __SHIFTOUT_MASK(ADMPCI_TAG_FUNCTION_MASK))
292320845ddSdyoung panic("%s: bad request", __func__);
293320845ddSdyoung
294320845ddSdyoung return __SHIFTIN(bus, ADMPCI_TAG_BUS_MASK) |
295320845ddSdyoung __SHIFTIN(device, ADMPCI_TAG_DEVICE_MASK) |
296320845ddSdyoung __SHIFTIN(function, ADMPCI_TAG_FUNCTION_MASK);
297320845ddSdyoung }
298320845ddSdyoung
299320845ddSdyoung void
admpci_decompose_tag(void * v,pcitag_t tag,int * b,int * d,int * f)300320845ddSdyoung admpci_decompose_tag(void *v, pcitag_t tag, int *b, int *d, int *f)
301320845ddSdyoung {
302320845ddSdyoung int bus, device, function;
303320845ddSdyoung
304320845ddSdyoung bus = __SHIFTOUT(tag, ADMPCI_TAG_BUS_MASK);
305320845ddSdyoung device = __SHIFTOUT(tag, ADMPCI_TAG_DEVICE_MASK);
306320845ddSdyoung function = __SHIFTOUT(tag, ADMPCI_TAG_FUNCTION_MASK);
307320845ddSdyoung
308320845ddSdyoung if (b != NULL)
309320845ddSdyoung *b = bus;
310320845ddSdyoung if (d != NULL)
311320845ddSdyoung *d = device;
312320845ddSdyoung if (f != NULL)
313320845ddSdyoung *f = function;
314320845ddSdyoung }
315320845ddSdyoung
316320845ddSdyoung static int
admpci_tag_to_addr(void * v,pcitag_t tag,int reg,bus_addr_t * addrp)317320845ddSdyoung admpci_tag_to_addr(void *v, pcitag_t tag, int reg, bus_addr_t *addrp)
318320845ddSdyoung {
319320845ddSdyoung int bus, device, function;
320320845ddSdyoung
321320845ddSdyoung KASSERT(addrp != NULL);
322605f564fSmsaitoh
323605f564fSmsaitoh if ((unsigned int)reg >= PCI_CONF_SIZE)
324605f564fSmsaitoh return -1;
325605f564fSmsaitoh
326320845ddSdyoung /* panics if tag is not well-formed */
327320845ddSdyoung admpci_decompose_tag(v, tag, &bus, &device, &function);
328320845ddSdyoung if (reg > __SHIFTOUT_MASK(ADMPCI_TAG_REGISTER_MASK))
329320845ddSdyoung panic("%s: bad register", __func__);
330320845ddSdyoung
331320845ddSdyoung *addrp = 0x80000000 | tag | __SHIFTIN(reg, ADMPCI_TAG_REGISTER_MASK);
332320845ddSdyoung
333320845ddSdyoung return 0;
334320845ddSdyoung }
335320845ddSdyoung
336320845ddSdyoung static pcireg_t
admpci_conf_read(void * v,pcitag_t tag,int reg)337320845ddSdyoung admpci_conf_read(void *v, pcitag_t tag, int reg)
338320845ddSdyoung {
339320845ddSdyoung int s;
340320845ddSdyoung struct admpci_softc *sc = (struct admpci_softc *)v;
341320845ddSdyoung uint32_t data;
342320845ddSdyoung bus_addr_t addr;
343320845ddSdyoung
344320845ddSdyoung ADMPCI_DPRINTF("%s: sc %p tag %lx reg %d\n", __func__, (void *)sc, tag,
345320845ddSdyoung reg);
346320845ddSdyoung
347320845ddSdyoung if (admpci_tag_to_addr(v, tag, reg, &addr) == -1)
348320845ddSdyoung return 0xffffffff;
349320845ddSdyoung
350320845ddSdyoung ADMPCI_DPRINTF("%s: sc_addrh %lx sc_datah %lx addr %lx\n", __func__,
351320845ddSdyoung sc->sc_addrh, sc->sc_datah, addr);
352320845ddSdyoung
353320845ddSdyoung s = splhigh();
354320845ddSdyoung bus_space_write_4(sc->sc_conft, sc->sc_addrh, 0, addr);
355320845ddSdyoung data = bus_space_read_4(sc->sc_conft, sc->sc_datah, 0);
356320845ddSdyoung splx(s);
357320845ddSdyoung
358320845ddSdyoung ADMPCI_DPRINTF("%s: read 0x%" PRIx32 "\n", __func__, data);
359320845ddSdyoung return data;
360320845ddSdyoung }
361320845ddSdyoung
362320845ddSdyoung void
admpci_conf_write(void * v,pcitag_t tag,int reg,pcireg_t data)363320845ddSdyoung admpci_conf_write(void *v, pcitag_t tag, int reg, pcireg_t data)
364320845ddSdyoung {
365320845ddSdyoung int s;
366320845ddSdyoung struct admpci_softc *sc = (struct admpci_softc *)v;
367320845ddSdyoung bus_addr_t addr;
368320845ddSdyoung
369320845ddSdyoung ADMPCI_DPRINTF("%s: sc %p tag %lx reg %d\n", __func__, (void *)sc, tag,
370320845ddSdyoung reg);
371320845ddSdyoung
372320845ddSdyoung if (admpci_tag_to_addr(v, tag, reg, &addr) == -1)
373320845ddSdyoung return;
374320845ddSdyoung
375320845ddSdyoung ADMPCI_DPRINTF("%s: sc_addrh %lx sc_datah %lx addr %lx\n", __func__,
376320845ddSdyoung sc->sc_addrh, sc->sc_datah, addr);
377320845ddSdyoung
378320845ddSdyoung s = splhigh();
379320845ddSdyoung bus_space_write_4(sc->sc_conft, sc->sc_addrh, 0, addr);
380320845ddSdyoung bus_space_write_4(sc->sc_conft, sc->sc_datah, 0, data);
381320845ddSdyoung splx(s);
382320845ddSdyoung }
383320845ddSdyoung
384320845ddSdyoung const char *
admpci_intr_string(void * v,pci_intr_handle_t ih,char * buf,size_t len)385e58a356cSchristos admpci_intr_string(void *v, pci_intr_handle_t ih, char *buf, size_t len)
386320845ddSdyoung {
387e58a356cSchristos (void)snprintf(buf, len, "irq %u", (unsigned)ih);
388e58a356cSchristos return buf;
389320845ddSdyoung }
390320845ddSdyoung
391320845ddSdyoung void *
admpci_intr_establish(void * v,pci_intr_handle_t ih,int ipl,int (* handler)(void *),void * arg)392320845ddSdyoung admpci_intr_establish(void *v, pci_intr_handle_t ih, int ipl,
393320845ddSdyoung int (*handler)(void *), void *arg)
394320845ddSdyoung {
395320845ddSdyoung return adm5120_intr_establish(ih, ipl, handler, arg);
396320845ddSdyoung }
397320845ddSdyoung
398320845ddSdyoung void
admpci_intr_disestablish(void * v,void * cookie)399320845ddSdyoung admpci_intr_disestablish(void *v, void *cookie)
400320845ddSdyoung {
401320845ddSdyoung adm5120_intr_disestablish(cookie);
402320845ddSdyoung }
403320845ddSdyoung
404320845ddSdyoung void
admpci_conf_interrupt(void * v,int bus,int dev,int ipin,int swiz,int * iline)405320845ddSdyoung admpci_conf_interrupt(void *v, int bus, int dev, int ipin, int swiz, int *iline)
406320845ddSdyoung {
407320845ddSdyoung /*
408320845ddSdyoung * We let the machdep_pci_intr_map take care of IRQ routing.
409320845ddSdyoung * On some platforms the BIOS may have handled this properly,
410320845ddSdyoung * on others it might not have. For now we avoid clobbering
411320845ddSdyoung * the settings establishsed by the BIOS, so that they will be
412320845ddSdyoung * there if the platform logic is confident that it can rely
413320845ddSdyoung * on them.
414320845ddSdyoung */
415320845ddSdyoung }
416320845ddSdyoung
417320845ddSdyoung /*
418320845ddSdyoung * Map the bus 0 device numbers 1, 2, and 3 to IRQ 6, 7, and 8,
419320845ddSdyoung * respectively.
420320845ddSdyoung *
421320845ddSdyoung * XXX How to handle bridges?
422320845ddSdyoung */
423320845ddSdyoung static int
admpci_intr_map(const struct pci_attach_args * pa,pci_intr_handle_t * ihp)424d3e53912Sdyoung admpci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
425320845ddSdyoung {
426320845ddSdyoung int bus, device, function;
427320845ddSdyoung
428320845ddSdyoung admpci_decompose_tag(pa->pa_pc->pc_conf_v, pa->pa_tag,
429320845ddSdyoung &bus, &device, &function);
430320845ddSdyoung
431320845ddSdyoung if (bus != 0 || device > 3)
432320845ddSdyoung return -1;
433320845ddSdyoung
434320845ddSdyoung *ihp = (device - 1) + 6;
435320845ddSdyoung
436320845ddSdyoung return 0;
437320845ddSdyoung }
438320845ddSdyoung #endif
439