1*c7fb772bSthorpej /* $NetBSD: vtpbc_mainbus.c,v 1.21 2021/08/07 16:18:40 thorpej Exp $ */
216b9c606Sthorpej
316b9c606Sthorpej /*-
416b9c606Sthorpej * Copyright (c) 2001 The NetBSD Foundation, Inc.
516b9c606Sthorpej * All rights reserved.
616b9c606Sthorpej *
716b9c606Sthorpej * This code is derived from software contributed to The NetBSD Foundation
816b9c606Sthorpej * by Jason R. Thorpe.
916b9c606Sthorpej *
1016b9c606Sthorpej * Redistribution and use in source and binary forms, with or without
1116b9c606Sthorpej * modification, are permitted provided that the following conditions
1216b9c606Sthorpej * are met:
1316b9c606Sthorpej * 1. Redistributions of source code must retain the above copyright
1416b9c606Sthorpej * notice, this list of conditions and the following disclaimer.
1516b9c606Sthorpej * 2. Redistributions in binary form must reproduce the above copyright
1616b9c606Sthorpej * notice, this list of conditions and the following disclaimer in the
1716b9c606Sthorpej * documentation and/or other materials provided with the distribution.
1816b9c606Sthorpej *
1916b9c606Sthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2016b9c606Sthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2116b9c606Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2216b9c606Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2316b9c606Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2416b9c606Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2516b9c606Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2616b9c606Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2716b9c606Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2816b9c606Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2916b9c606Sthorpej * POSSIBILITY OF SUCH DAMAGE.
3016b9c606Sthorpej */
3116b9c606Sthorpej
326fdfc66cSlukem #include <sys/cdefs.h>
33*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: vtpbc_mainbus.c,v 1.21 2021/08/07 16:18:40 thorpej Exp $");
346fdfc66cSlukem
3516b9c606Sthorpej #include "opt_algor_p4032.h"
3616b9c606Sthorpej #include "opt_algor_p5064.h"
3716b9c606Sthorpej
3816b9c606Sthorpej #include <sys/param.h>
39391925c7Sdyoung #include <sys/bus.h>
40f5439ed7Smatt #include <sys/conf.h>
41f5439ed7Smatt #include <sys/device.h>
42f5439ed7Smatt #include <sys/reboot.h>
43f5439ed7Smatt #include <sys/systm.h>
44f5439ed7Smatt
45f5439ed7Smatt #include <algor/autoconf.h>
4616b9c606Sthorpej
4716b9c606Sthorpej #include <algor/pci/vtpbcvar.h>
4816b9c606Sthorpej
4916b9c606Sthorpej #ifdef ALGOR_P4032
5016b9c606Sthorpej #include <algor/algor/algor_p4032var.h>
5116b9c606Sthorpej #endif
5216b9c606Sthorpej
5316b9c606Sthorpej #ifdef ALGOR_P5064
5416b9c606Sthorpej #include <algor/algor/algor_p5064var.h>
5516b9c606Sthorpej #endif
5616b9c606Sthorpej
5716b9c606Sthorpej struct vtpbc_softc {
5816b9c606Sthorpej struct vtpbc_config *sc_vtpbc;
5916b9c606Sthorpej };
6016b9c606Sthorpej
61cbab9cadSchs int vtpbc_mainbus_match(device_t, cfdata_t, void *);
62cbab9cadSchs void vtpbc_mainbus_attach(device_t, device_t, void *);
6316b9c606Sthorpej
64cbab9cadSchs CFATTACH_DECL_NEW(vtpbc_mainbus, sizeof(struct vtpbc_softc),
655a9ddc14Sthorpej vtpbc_mainbus_match, vtpbc_mainbus_attach, NULL, NULL);
6616b9c606Sthorpej extern struct cfdriver vtpbc_cd;
6716b9c606Sthorpej
6816b9c606Sthorpej int
vtpbc_mainbus_match(device_t parent,cfdata_t cf,void * aux)69cbab9cadSchs vtpbc_mainbus_match(device_t parent, cfdata_t cf, void *aux)
7016b9c606Sthorpej {
7116b9c606Sthorpej struct mainbus_attach_args *ma = aux;
7216b9c606Sthorpej
7316b9c606Sthorpej if (strcmp(ma->ma_name, vtpbc_cd.cd_name) == 0)
7416b9c606Sthorpej return (1);
7516b9c606Sthorpej
7616b9c606Sthorpej return (0);
7716b9c606Sthorpej }
7816b9c606Sthorpej
7916b9c606Sthorpej void
vtpbc_mainbus_attach(device_t parent,device_t self,void * aux)80cbab9cadSchs vtpbc_mainbus_attach(device_t parent, device_t self, void *aux)
8116b9c606Sthorpej {
82cbab9cadSchs struct vtpbc_softc *sc = device_private(self);
8316b9c606Sthorpej struct pcibus_attach_args pba;
8416b9c606Sthorpej struct vtpbc_config *vt;
8516b9c606Sthorpej
8616b9c606Sthorpej /*
8716b9c606Sthorpej * There is only one PCI controller on an Algorithmics board.
8816b9c606Sthorpej */
8916b9c606Sthorpej vt = &vtpbc_configuration;
9016b9c606Sthorpej sc->sc_vtpbc = vt;
9116b9c606Sthorpej
9216b9c606Sthorpej if (vt->vt_rev < vtpbc_nrevs)
9316b9c606Sthorpej printf(": V3 V962, revision %s\n", vtpbc_revs[vt->vt_rev]);
9416b9c606Sthorpej else
9516b9c606Sthorpej printf(": V3 V962, unknown revision %d\n", vt->vt_rev);
9616b9c606Sthorpej
97cbab9cadSchs printf("%s: PCI memory space base: 0x%08lx\n", device_xname(self),
9880dfaa3eSthorpej (u_long) vt->vt_pci_membase);
99cbab9cadSchs printf("%s: PCI DMA window base: 0x%08lx\n", device_xname(self),
10080dfaa3eSthorpej (u_long) vt->vt_dma_winbase);
10180dfaa3eSthorpej
102a6b2b839Sdyoung pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY;
10316b9c606Sthorpej pba.pba_bus = 0;
104204183c0Sthorpej pba.pba_bridgetag = NULL;
105fe87c9aaSthorpej
106fe87c9aaSthorpej if (vt->vt_pci_iobase == (bus_addr_t) -1)
107a6b2b839Sdyoung pba.pba_flags &= ~PCI_FLAGS_IO_OKAY;
108fe87c9aaSthorpej
10916b9c606Sthorpej #if defined(ALGOR_P4032)
11016b9c606Sthorpej {
11116b9c606Sthorpej struct p4032_config *acp = &p4032_configuration;
11216b9c606Sthorpej
11316b9c606Sthorpej pba.pba_iot = &acp->ac_iot;
11416b9c606Sthorpej pba.pba_memt = &acp->ac_memt;
1151930cfd7Sthorpej pba.pba_dmat = &acp->ac_pci_dmat;
1167dd7f8baSfvdl pba.pba_dmat64 = NULL;
11716b9c606Sthorpej pba.pba_pc = &acp->ac_pc;
11816b9c606Sthorpej }
11916b9c606Sthorpej #elif defined(ALGOR_P5064)
12016b9c606Sthorpej {
12116b9c606Sthorpej struct p5064_config *acp = &p5064_configuration;
12216b9c606Sthorpej
12316b9c606Sthorpej pba.pba_iot = &acp->ac_iot;
12416b9c606Sthorpej pba.pba_memt = &acp->ac_memt;
12516b9c606Sthorpej pba.pba_dmat = &acp->ac_pci_dmat;
1267dd7f8baSfvdl pba.pba_dmat64 = NULL;
12716b9c606Sthorpej pba.pba_pc = &acp->ac_pc;
12816b9c606Sthorpej }
12916b9c606Sthorpej #endif /* ALGOR_P4032 || ALGOR_P5064 */
13016b9c606Sthorpej
131*c7fb772bSthorpej config_found(self, &pba, pcibusprint, CFARGS_NONE);
13216b9c606Sthorpej }
133