1*c7fb772bSthorpej /* $NetBSD: pcib.c,v 1.18 2021/08/07 16:18:47 thorpej Exp $ */
20a162278Schris
30a162278Schris /*-
40a162278Schris * Copyright (c) 1996, 1998 The NetBSD Foundation, Inc.
50a162278Schris * All rights reserved.
60a162278Schris *
70a162278Schris * This code is derived from software contributed to The NetBSD Foundation
80a162278Schris * by Jason R. Thorpe.
90a162278Schris *
100a162278Schris * Redistribution and use in source and binary forms, with or without
110a162278Schris * modification, are permitted provided that the following conditions
120a162278Schris * are met:
130a162278Schris * 1. Redistributions of source code must retain the above copyright
140a162278Schris * notice, this list of conditions and the following disclaimer.
150a162278Schris * 2. Redistributions in binary form must reproduce the above copyright
160a162278Schris * notice, this list of conditions and the following disclaimer in the
170a162278Schris * documentation and/or other materials provided with the distribution.
180a162278Schris *
190a162278Schris * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
200a162278Schris * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
210a162278Schris * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
220a162278Schris * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
230a162278Schris * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
240a162278Schris * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
250a162278Schris * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
260a162278Schris * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
270a162278Schris * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
280a162278Schris * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
290a162278Schris * POSSIBILITY OF SUCH DAMAGE.
300a162278Schris *
310a162278Schris * from: i386/pci/pcib.c,v 1.12
320a162278Schris */
330a162278Schris
34e803bea7Slukem #include <sys/cdefs.h>
35*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: pcib.c,v 1.18 2021/08/07 16:18:47 thorpej Exp $");
36e803bea7Slukem
370a162278Schris #include <sys/param.h>
380a162278Schris #include <sys/systm.h>
390a162278Schris #include <sys/device.h>
400a162278Schris
41ed9977b1Sdyoung #include <sys/bus.h>
420a162278Schris
430a162278Schris #include <dev/isa/isavar.h>
440a162278Schris
450a162278Schris #include <dev/pci/pcivar.h>
460a162278Schris #include <dev/pci/pcireg.h>
470a162278Schris
480a162278Schris #include <dev/pci/pcidevs.h>
490a162278Schris
500a162278Schris #include "isadma.h"
510a162278Schris
52338de10aSmatt int pcibmatch(device_t, cfdata_t, void *);
53338de10aSmatt void pcibattach(device_t, device_t, void *);
540a162278Schris
55338de10aSmatt CFATTACH_DECL_NEW(pcib, 0,
56c5e91d44Sthorpej pcibmatch, pcibattach, NULL, NULL);
570a162278Schris
58338de10aSmatt void pcib_callback(device_t);
590a162278Schris
600a162278Schris int
pcibmatch(device_t parent,cfdata_t match,void * aux)61338de10aSmatt pcibmatch(device_t parent, cfdata_t match, void *aux)
620a162278Schris {
630a162278Schris struct pci_attach_args *pa = aux;
640a162278Schris
650a162278Schris /*
660a162278Schris * Match tested PCI-ISA bridges.
670a162278Schris */
680a162278Schris switch (PCI_VENDOR(pa->pa_id)) {
690a162278Schris case PCI_VENDOR_ALI:
700a162278Schris switch (PCI_PRODUCT(pa->pa_id)) {
71465f44f4Sskrll case PCI_PRODUCT_ALI_M1533:
720a162278Schris return (1);
730a162278Schris }
740a162278Schris break;
750a162278Schris }
760a162278Schris
770a162278Schris return (0);
780a162278Schris }
790a162278Schris
800a162278Schris void
pcibattach(device_t parent,device_t self,void * aux)81338de10aSmatt pcibattach(device_t parent, device_t self, void *aux)
820a162278Schris {
830a162278Schris struct pci_attach_args *pa = aux;
840a162278Schris char devinfo[256];
850a162278Schris
860a162278Schris printf("\n");
870a162278Schris
880a162278Schris /*
890a162278Schris * Just print out a description and set the ISA bus
900a162278Schris * callback.
910a162278Schris */
9261230437Sitojun pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo, sizeof(devinfo));
93cbab9cadSchs printf("%s: %s (rev. 0x%02x)\n", device_xname(self), devinfo,
940a162278Schris PCI_REVISION(pa->pa_class));
950a162278Schris
960a162278Schris /* Set the ISA bus callback */
970a162278Schris config_defer(self, pcib_callback);
980a162278Schris }
990a162278Schris
1000a162278Schris void
pcib_callback(device_t self)101338de10aSmatt pcib_callback(device_t self)
1020a162278Schris {
1030a162278Schris struct isabus_attach_args iba;
1040a162278Schris
1050a162278Schris /*
1060a162278Schris * Attach the ISA bus behind this bridge.
1070a162278Schris */
1080a162278Schris memset(&iba, 0, sizeof(iba));
1090a162278Schris iba.iba_iot = &isa_io_bs_tag;
1100a162278Schris iba.iba_memt = &isa_mem_bs_tag;
1110a162278Schris #if NISADMA > 0
1120a162278Schris iba.iba_dmat = &isa_bus_dma_tag;
1130a162278Schris #endif
114*c7fb772bSthorpej config_found(self, &iba, isabusprint, CFARGS_NONE);
1150a162278Schris }
116