1*c7fb772bSthorpej /* $NetBSD: bonito_mainbus.c,v 1.19 2021/08/07 16:18:40 thorpej Exp $ */
2498641fcSthorpej
3498641fcSthorpej /*-
4498641fcSthorpej * Copyright (c) 2001 The NetBSD Foundation, Inc.
5498641fcSthorpej * All rights reserved.
6498641fcSthorpej *
7498641fcSthorpej * This code is derived from software contributed to The NetBSD Foundation
8498641fcSthorpej * by Jason R. Thorpe.
9498641fcSthorpej *
10498641fcSthorpej * Redistribution and use in source and binary forms, with or without
11498641fcSthorpej * modification, are permitted provided that the following conditions
12498641fcSthorpej * are met:
13498641fcSthorpej * 1. Redistributions of source code must retain the above copyright
14498641fcSthorpej * notice, this list of conditions and the following disclaimer.
15498641fcSthorpej * 2. Redistributions in binary form must reproduce the above copyright
16498641fcSthorpej * notice, this list of conditions and the following disclaimer in the
17498641fcSthorpej * documentation and/or other materials provided with the distribution.
18498641fcSthorpej *
19498641fcSthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20498641fcSthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21498641fcSthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22498641fcSthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23498641fcSthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24498641fcSthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25498641fcSthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26498641fcSthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27498641fcSthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28498641fcSthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29498641fcSthorpej * POSSIBILITY OF SUCH DAMAGE.
30498641fcSthorpej */
31498641fcSthorpej
326fdfc66cSlukem #include <sys/cdefs.h>
33*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: bonito_mainbus.c,v 1.19 2021/08/07 16:18:40 thorpej Exp $");
346fdfc66cSlukem
35498641fcSthorpej #include "opt_algor_p6032.h"
36498641fcSthorpej
37498641fcSthorpej #include <sys/param.h>
38391925c7Sdyoung #include <sys/bus.h>
39f5439ed7Smatt #include <sys/conf.h>
40f5439ed7Smatt #include <sys/device.h>
41f5439ed7Smatt #include <sys/reboot.h>
42f5439ed7Smatt #include <sys/systm.h>
43f5439ed7Smatt
44f5439ed7Smatt #include <algor/autoconf.h>
45498641fcSthorpej
46b3a5c565Smatt #include <mips/cpuregs.h>
47498641fcSthorpej #include <mips/bonito/bonitoreg.h>
48498641fcSthorpej
49498641fcSthorpej #ifdef ALGOR_P6032
50498641fcSthorpej #include <algor/algor/algor_p6032var.h>
51498641fcSthorpej #endif
52498641fcSthorpej
53498641fcSthorpej struct bonito_softc {
54498641fcSthorpej struct bonito_config *sc_bonito;
55498641fcSthorpej };
56498641fcSthorpej
57cbab9cadSchs int bonito_mainbus_match(device_t, cfdata_t, void *);
58cbab9cadSchs void bonito_mainbus_attach(device_t, device_t, void *);
59498641fcSthorpej
60cbab9cadSchs CFATTACH_DECL_NEW(bonito_mainbus, sizeof(struct bonito_softc),
615a9ddc14Sthorpej bonito_mainbus_match, bonito_mainbus_attach, NULL, NULL);
62498641fcSthorpej extern struct cfdriver bonito_cd;
63498641fcSthorpej
64498641fcSthorpej int
bonito_mainbus_match(device_t parent,cfdata_t cf,void * aux)65cbab9cadSchs bonito_mainbus_match(device_t parent, cfdata_t cf, void *aux)
66498641fcSthorpej {
67498641fcSthorpej struct mainbus_attach_args *ma = aux;
68498641fcSthorpej
69498641fcSthorpej if (strcmp(ma->ma_name, bonito_cd.cd_name) == 0)
70498641fcSthorpej return (1);
71498641fcSthorpej
72498641fcSthorpej return (0);
73498641fcSthorpej }
74498641fcSthorpej
75498641fcSthorpej void
bonito_mainbus_attach(device_t parent,device_t self,void * aux)76cbab9cadSchs bonito_mainbus_attach(device_t parent, device_t self, void *aux)
77498641fcSthorpej {
78cbab9cadSchs struct bonito_softc *sc = device_private(self);
79498641fcSthorpej struct pcibus_attach_args pba;
80498641fcSthorpej struct bonito_config *bc;
81498641fcSthorpej pcireg_t rev;
82498641fcSthorpej
83498641fcSthorpej /*
84498641fcSthorpej * There is only one PCI controller on an Algorithmics board.
85498641fcSthorpej */
86498641fcSthorpej #if defined(ALGOR_P6032)
87498641fcSthorpej bc = &p6032_configuration.ac_bonito;
8810fabf63Sdholland #else
8910fabf63Sdholland /* I guess... XXX? */
9010fabf63Sdholland bc = NULL;
91498641fcSthorpej #endif
92498641fcSthorpej sc->sc_bonito = bc;
93498641fcSthorpej
94498641fcSthorpej rev = PCI_REVISION(REGVAL(BONITO_PCICLASS));
95498641fcSthorpej
96498641fcSthorpej printf(": BONITO Memory and PCI controller, %s rev. %d.%d\n",
97498641fcSthorpej BONITO_REV_FPGA(rev) ? "FPGA" : "ASIC",
98498641fcSthorpej BONITO_REV_MAJOR(rev), BONITO_REV_MINOR(rev));
99498641fcSthorpej
100a6b2b839Sdyoung pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY;
101498641fcSthorpej pba.pba_bus = 0;
102204183c0Sthorpej pba.pba_bridgetag = NULL;
103498641fcSthorpej
104498641fcSthorpej #if defined(ALGOR_P6032)
105498641fcSthorpej {
106498641fcSthorpej struct p6032_config *acp = &p6032_configuration;
107498641fcSthorpej
108498641fcSthorpej pba.pba_iot = &acp->ac_iot;
109498641fcSthorpej pba.pba_memt = &acp->ac_memt;
110498641fcSthorpej pba.pba_dmat = &acp->ac_pci_dmat;
1117dd7f8baSfvdl pba.pba_dmat64 = NULL;
112498641fcSthorpej pba.pba_pc = &acp->ac_pc;
113498641fcSthorpej }
114498641fcSthorpej #endif /* ALGOR_P6032 */
115498641fcSthorpej
116*c7fb772bSthorpej config_found(self, &pba, pcibusprint, CFARGS_NONE);
117498641fcSthorpej }
118