Thu Mar 3 06:27:21 2022 UTC ()
mips: Use device_set_private in a few drivers.


(riastradh)
diff -r1.5 -r1.6 src/sys/arch/evbmips/gdium/bonito_mainbus.c
diff -r1.5 -r1.6 src/sys/arch/evbmips/loongson/bonito_mainbus.c
diff -r1.8 -r1.9 src/sys/arch/mips/sibyte/pci/sbbrz.c

cvs diff -r1.5 -r1.6 src/sys/arch/evbmips/gdium/bonito_mainbus.c (switch to unified diff)

--- src/sys/arch/evbmips/gdium/bonito_mainbus.c 2021/08/07 16:18:51 1.5
+++ src/sys/arch/evbmips/gdium/bonito_mainbus.c 2022/03/03 06:27:20 1.6
@@ -1,96 +1,96 @@ @@ -1,96 +1,96 @@
1/* $NetBSD: bonito_mainbus.c,v 1.5 2021/08/07 16:18:51 thorpej Exp $ */ 1/* $NetBSD: bonito_mainbus.c,v 1.6 2022/03/03 06:27:20 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc. 4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe. 8 * by Jason R. Thorpe.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: bonito_mainbus.c,v 1.5 2021/08/07 16:18:51 thorpej Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: bonito_mainbus.c,v 1.6 2022/03/03 06:27:20 riastradh Exp $");
34 34
35#include <sys/param.h> 35#include <sys/param.h>
36#include <sys/systm.h> 36#include <sys/systm.h>
37#include <sys/conf.h> 37#include <sys/conf.h>
38#include <sys/reboot.h> 38#include <sys/reboot.h>
39#include <sys/device.h> 39#include <sys/device.h>
40 40
41#include <sys/bus.h> 41#include <sys/bus.h>
42 42
43#include <mips/bonito/bonitoreg.h> 43#include <mips/bonito/bonitoreg.h>
44 44
45#include <evbmips/gdium/gdiumvar.h> 45#include <evbmips/gdium/gdiumvar.h>
46 46
47static int bonito_mainbus_match(device_t, cfdata_t, void *); 47static int bonito_mainbus_match(device_t, cfdata_t, void *);
48static void bonito_mainbus_attach(device_t, device_t, void *); 48static void bonito_mainbus_attach(device_t, device_t, void *);
49 49
50CFATTACH_DECL_NEW(bonito_mainbus, 0, 50CFATTACH_DECL_NEW(bonito_mainbus, 0,
51 bonito_mainbus_match, bonito_mainbus_attach, NULL, NULL); 51 bonito_mainbus_match, bonito_mainbus_attach, NULL, NULL);
52 52
53extern struct cfdriver bonito_cd; 53extern struct cfdriver bonito_cd;
54 54
55int 55int
56bonito_mainbus_match(device_t parent, cfdata_t cf, void *aux) 56bonito_mainbus_match(device_t parent, cfdata_t cf, void *aux)
57{ 57{
58 struct mainbus_attach_args * const maa = aux; 58 struct mainbus_attach_args * const maa = aux;
59 59
60 if (strcmp(maa->maa_name, bonito_cd.cd_name) == 0) 60 if (strcmp(maa->maa_name, bonito_cd.cd_name) == 0)
61 return (1); 61 return (1);
62 62
63 return (0); 63 return (0);
64} 64}
65 65
66void 66void
67bonito_mainbus_attach(device_t parent, device_t self, void *aux) 67bonito_mainbus_attach(device_t parent, device_t self, void *aux)
68{ 68{
69 struct pcibus_attach_args pba; 69 struct pcibus_attach_args pba;
70 struct gdium_config * const gc = &gdium_configuration; 70 struct gdium_config * const gc = &gdium_configuration;
71 pcireg_t rev; 71 pcireg_t rev;
72 72
73 self->dv_private = &gc->gc_bonito; 73 device_set_private(self, &gc->gc_bonito);
74 74
75 /* 75 /*
76 * There is only one PCI controller on a Loongson chip. 76 * There is only one PCI controller on a Loongson chip.
77 */ 77 */
78 78
79 rev = PCI_REVISION(REGVAL(BONITO_PCICLASS)); 79 rev = PCI_REVISION(REGVAL(BONITO_PCICLASS));
80 80
81 printf(": BONITO Memory and PCI controller, %s rev. %d.%d\n", 81 printf(": BONITO Memory and PCI controller, %s rev. %d.%d\n",
82 BONITO_REV_FPGA(rev) ? "FPGA" : "ASIC", 82 BONITO_REV_FPGA(rev) ? "FPGA" : "ASIC",
83 BONITO_REV_MAJOR(rev), BONITO_REV_MINOR(rev)); 83 BONITO_REV_MAJOR(rev), BONITO_REV_MINOR(rev));
84 84
85 pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY; 85 pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY;
86 pba.pba_bus = 0; 86 pba.pba_bus = 0;
87 pba.pba_bridgetag = NULL; 87 pba.pba_bridgetag = NULL;
88 88
89 pba.pba_iot = &gc->gc_iot; 89 pba.pba_iot = &gc->gc_iot;
90 pba.pba_memt = &gc->gc_memt; 90 pba.pba_memt = &gc->gc_memt;
91 pba.pba_dmat = &gc->gc_pci_dmat; 91 pba.pba_dmat = &gc->gc_pci_dmat;
92 pba.pba_dmat64 = NULL; 92 pba.pba_dmat64 = NULL;
93 pba.pba_pc = &gc->gc_pc; 93 pba.pba_pc = &gc->gc_pc;
94 94
95 config_found(self, &pba, pcibusprint, CFARGS_NONE); 95 config_found(self, &pba, pcibusprint, CFARGS_NONE);
96} 96}

cvs diff -r1.5 -r1.6 src/sys/arch/evbmips/loongson/bonito_mainbus.c (switch to unified diff)

--- src/sys/arch/evbmips/loongson/bonito_mainbus.c 2021/08/07 16:18:51 1.5
+++ src/sys/arch/evbmips/loongson/bonito_mainbus.c 2022/03/03 06:27:21 1.6
@@ -1,118 +1,118 @@ @@ -1,118 +1,118 @@
1/* $NetBSD: bonito_mainbus.c,v 1.5 2021/08/07 16:18:51 thorpej Exp $ */ 1/* $NetBSD: bonito_mainbus.c,v 1.6 2022/03/03 06:27:21 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc. 4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe. 8 * by Jason R. Thorpe.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: bonito_mainbus.c,v 1.5 2021/08/07 16:18:51 thorpej Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: bonito_mainbus.c,v 1.6 2022/03/03 06:27:21 riastradh Exp $");
34 34
35#include <sys/param.h> 35#include <sys/param.h>
36#include <sys/systm.h> 36#include <sys/systm.h>
37#include <sys/conf.h> 37#include <sys/conf.h>
38#include <sys/reboot.h> 38#include <sys/reboot.h>
39#include <sys/device.h> 39#include <sys/device.h>
40 40
41#include <sys/bus.h> 41#include <sys/bus.h>
42 42
43#include <mips/cpuregs.h> 43#include <mips/cpuregs.h>
44#include <mips/bonito/bonitoreg.h> 44#include <mips/bonito/bonitoreg.h>
45 45
46#include <evbmips/loongson/autoconf.h> 46#include <evbmips/loongson/autoconf.h>
47#include <evbmips/loongson/loongson_bus_defs.h> 47#include <evbmips/loongson/loongson_bus_defs.h>
48#include <dev/pci/pcivar.h> 48#include <dev/pci/pcivar.h>
49 49
50static int bonito_mainbus_match(device_t, cfdata_t, void *); 50static int bonito_mainbus_match(device_t, cfdata_t, void *);
51static void bonito_mainbus_attach(device_t, device_t, void *); 51static void bonito_mainbus_attach(device_t, device_t, void *);
52 52
53CFATTACH_DECL_NEW(bonito_mainbus, 0, 53CFATTACH_DECL_NEW(bonito_mainbus, 0,
54 bonito_mainbus_match, bonito_mainbus_attach, NULL, NULL); 54 bonito_mainbus_match, bonito_mainbus_attach, NULL, NULL);
55 55
56extern struct cfdriver bonito_cd; 56extern struct cfdriver bonito_cd;
57 57
58int 58int
59bonito_mainbus_match(device_t parent, cfdata_t cf, void *aux) 59bonito_mainbus_match(device_t parent, cfdata_t cf, void *aux)
60{ 60{
61 struct mainbus_attach_args * const maa = aux; 61 struct mainbus_attach_args * const maa = aux;
62 62
63 if (strcmp(maa->maa_name, bonito_cd.cd_name) == 0) 63 if (strcmp(maa->maa_name, bonito_cd.cd_name) == 0)
64 return (1); 64 return (1);
65 65
66 return (0); 66 return (0);
67} 67}
68 68
69void 69void
70bonito_mainbus_attach(device_t parent, device_t self, void *aux) 70bonito_mainbus_attach(device_t parent, device_t self, void *aux)
71{ 71{
72 struct pcibus_attach_args pba; 72 struct pcibus_attach_args pba;
73 pcireg_t rev; 73 pcireg_t rev;
74 bool compatible; 74 bool compatible;
75 75
76 self->dv_private = __UNCONST(&sys_platform->bonito_config); 76 device_set_private(self, __UNCONST(&sys_platform->bonito_config));
77 77
78 /* 78 /*
79 * Loongson 2F processors do not use a real Bonito64 chip but 79 * Loongson 2F processors do not use a real Bonito64 chip but
80 * their own derivative, which is no longer 100% compatible. 80 * their own derivative, which is no longer 100% compatible.
81 * We need to make sure we never try to access an unimplemented 81 * We need to make sure we never try to access an unimplemented
82 * register... 82 * register...
83 */ 83 */
84 if (loongson_ver >= 0x2f) 84 if (loongson_ver >= 0x2f)
85 compatible = false; 85 compatible = false;
86 else 86 else
87 compatible = true; 87 compatible = true;
88 88
89 /* 89 /*
90 * There is only one PCI controller on a Loongson chip. 90 * There is only one PCI controller on a Loongson chip.
91 */ 91 */
92 92
93 rev = PCI_REVISION(REGVAL(BONITO_PCICLASS)); 93 rev = PCI_REVISION(REGVAL(BONITO_PCICLASS));
94 if (compatible) { 94 if (compatible) {
95 aprint_normal(": BONITO Memory and PCI controller," 95 aprint_normal(": BONITO Memory and PCI controller,"
96 " %s rev. %d.%d\n", BONITO_REV_FPGA(rev) ? "FPGA" : "ASIC", 96 " %s rev. %d.%d\n", BONITO_REV_FPGA(rev) ? "FPGA" : "ASIC",
97 BONITO_REV_MAJOR(rev), BONITO_REV_MINOR(rev)); 97 BONITO_REV_MAJOR(rev), BONITO_REV_MINOR(rev));
98 } else { 98 } else {
99 aprint_normal(": Memory and PCI-X controller, rev. %d\n", 99 aprint_normal(": Memory and PCI-X controller, rev. %d\n",
100 PCI_REVISION(rev)); 100 PCI_REVISION(rev));
101 } 101 }
102 102
103 /* 103 /*
104 * Attach PCI bus. 104 * Attach PCI bus.
105 */ 105 */
106 106
107 pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY; 107 pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY;
108 pba.pba_bus = 0; 108 pba.pba_bus = 0;
109 pba.pba_bridgetag = NULL; 109 pba.pba_bridgetag = NULL;
110 110
111 pba.pba_iot = &bonito_iot; 111 pba.pba_iot = &bonito_iot;
112 pba.pba_memt = &bonito_memt; 112 pba.pba_memt = &bonito_memt;
113 pba.pba_dmat = &bonito_dmat; 113 pba.pba_dmat = &bonito_dmat;
114 pba.pba_dmat64 = NULL; 114 pba.pba_dmat64 = NULL;
115 pba.pba_pc = &bonito_pc; 115 pba.pba_pc = &bonito_pc;
116 116
117 config_found(self, &pba, pcibusprint, CFARGS_NONE); 117 config_found(self, &pba, pcibusprint, CFARGS_NONE);
118} 118}

cvs diff -r1.8 -r1.9 src/sys/arch/mips/sibyte/pci/sbbrz.c (switch to unified diff)

--- src/sys/arch/mips/sibyte/pci/sbbrz.c 2022/01/22 15:10:31 1.8
+++ src/sys/arch/mips/sibyte/pci/sbbrz.c 2022/03/03 06:27:21 1.9
@@ -1,221 +1,221 @@ @@ -1,221 +1,221 @@
1/* $NetBSD: sbbrz.c,v 1.8 2022/01/22 15:10:31 skrll Exp $ */ 1/* $NetBSD: sbbrz.c,v 1.9 2022/03/03 06:27:21 riastradh Exp $ */
2 2
3/* 3/*
4 * Copyright 2000, 2001 4 * Copyright 2000, 2001
5 * Broadcom Corporation. All rights reserved. 5 * Broadcom Corporation. All rights reserved.
6 * 6 *
7 * This software is furnished under license and may be used and copied only 7 * This software is furnished under license and may be used and copied only
8 * in accordance with the following terms and conditions. Subject to these 8 * in accordance with the following terms and conditions. Subject to these
9 * conditions, you may download, copy, install, use, modify and distribute 9 * conditions, you may download, copy, install, use, modify and distribute
10 * modified or unmodified copies of this software in source and/or binary 10 * modified or unmodified copies of this software in source and/or binary
11 * form. No title or ownership is transferred hereby. 11 * form. No title or ownership is transferred hereby.
12 * 12 *
13 * 1) Any source code used, modified or distributed must reproduce and 13 * 1) Any source code used, modified or distributed must reproduce and
14 * retain this copyright notice and list of conditions as they appear in 14 * retain this copyright notice and list of conditions as they appear in
15 * the source file. 15 * the source file.
16 * 16 *
17 * 2) No right is granted to use any trade name, trademark, or logo of 17 * 2) No right is granted to use any trade name, trademark, or logo of
18 * Broadcom Corporation. Neither the "Broadcom Corporation" name nor any 18 * Broadcom Corporation. Neither the "Broadcom Corporation" name nor any
19 * trademark or logo of Broadcom Corporation may be used to endorse or 19 * trademark or logo of Broadcom Corporation may be used to endorse or
20 * promote products derived from this software without the prior written 20 * promote products derived from this software without the prior written
21 * permission of Broadcom Corporation. 21 * permission of Broadcom Corporation.
22 * 22 *
23 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED 23 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
24 * WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF 24 * WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR 25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
26 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE 26 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
27 * FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE 27 * FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
28 * LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 28 * LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
31 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 31 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33 * OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 * OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */ 34 */
35 35
36/* from: $NetBSD: apecs.c,v 1.38 2000/06/29 08:58:45 mrg Exp */ 36/* from: $NetBSD: apecs.c,v 1.38 2000/06/29 08:58:45 mrg Exp */
37 37
38/*- 38/*-
39 * Copyright (c) 2000, 2010 The NetBSD Foundation, Inc. 39 * Copyright (c) 2000, 2010 The NetBSD Foundation, Inc.
40 * All rights reserved. 40 * All rights reserved.
41 * 41 *
42 * This code is derived from software contributed to The NetBSD Foundation 42 * This code is derived from software contributed to The NetBSD Foundation
43 * by Jason R. Thorpe. 43 * by Jason R. Thorpe.
44 * 44 *
45 * Redistribution and use in source and binary forms, with or without 45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions 46 * modification, are permitted provided that the following conditions
47 * are met: 47 * are met:
48 * 1. Redistributions of source code must retain the above copyright 48 * 1. Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer. 49 * notice, this list of conditions and the following disclaimer.
50 * 2. Redistributions in binary form must reproduce the above copyright 50 * 2. Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the 51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution. 52 * documentation and/or other materials provided with the distribution.
53 * 53 *
54 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 54 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
55 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 55 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
56 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 56 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 57 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
58 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 58 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
59 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 59 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
60 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 60 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
61 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 61 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
62 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 62 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
63 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 63 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
64 * POSSIBILITY OF SUCH DAMAGE. 64 * POSSIBILITY OF SUCH DAMAGE.
65 */ 65 */
66 66
67/* 67/*
68 * Copyright (c) 1995, 1996 Carnegie-Mellon University. 68 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
69 * All rights reserved. 69 * All rights reserved.
70 * 70 *
71 * Author: Chris G. Demetriou 71 * Author: Chris G. Demetriou
72 * 72 *
73 * Permission to use, copy, modify and distribute this software and 73 * Permission to use, copy, modify and distribute this software and
74 * its documentation is hereby granted, provided that both the copyright 74 * its documentation is hereby granted, provided that both the copyright
75 * notice and this permission notice appear in all copies of the 75 * notice and this permission notice appear in all copies of the
76 * software, derivative works or modified versions, and any portions 76 * software, derivative works or modified versions, and any portions
77 * thereof, and that both notices appear in supporting documentation. 77 * thereof, and that both notices appear in supporting documentation.
78 * 78 *
79 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 79 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
80 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 80 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
81 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 81 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
82 * 82 *
83 * Carnegie Mellon requests users of this software to return to 83 * Carnegie Mellon requests users of this software to return to
84 * 84 *
85 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 85 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
86 * School of Computer Science 86 * School of Computer Science
87 * Carnegie Mellon University 87 * Carnegie Mellon University
88 * Pittsburgh PA 15213-3890 88 * Pittsburgh PA 15213-3890
89 * 89 *
90 * any improvements or extensions that they make and grant Carnegie the 90 * any improvements or extensions that they make and grant Carnegie the
91 * rights to redistribute these changes. 91 * rights to redistribute these changes.
92 */ 92 */
93 93
94/* 94/*
95 * Driver for SB-1250 I/O bridge 0, which provides the PCI and LDT 95 * Driver for SB-1250 I/O bridge 0, which provides the PCI and LDT
96 * interfaces. 96 * interfaces.
97 */ 97 */
98 98
99#define _MIPS_BUS_DMA_PRIVATE 99#define _MIPS_BUS_DMA_PRIVATE
100 100
101#include <sys/param.h> 101#include <sys/param.h>
102#include <sys/device.h> 102#include <sys/device.h>
103#include <sys/systm.h> 103#include <sys/systm.h>
104#include <sys/bus.h> 104#include <sys/bus.h>
105 105
106#include <dev/pci/pcireg.h> 106#include <dev/pci/pcireg.h>
107#include <dev/pci/pcivar.h> 107#include <dev/pci/pcivar.h>
108#include <dev/pci/pcidevs.h> 108#include <dev/pci/pcidevs.h>
109 109
110#include <mips/locore.h> 110#include <mips/locore.h>
111#include <mips/sibyte/include/sb1250_regs.h> 111#include <mips/sibyte/include/sb1250_regs.h>
112#include <mips/sibyte/include/sb1250_scd.h> 112#include <mips/sibyte/include/sb1250_scd.h>
113#include <mips/sibyte/include/zbbusvar.h> 113#include <mips/sibyte/include/zbbusvar.h>
114#include <mips/sibyte/pci/sbbrzvar.h> 114#include <mips/sibyte/pci/sbbrzvar.h>
115 115
116static int sbbrz_match(device_t, cfdata_t, void *); 116static int sbbrz_match(device_t, cfdata_t, void *);
117static void sbbrz_attach(device_t, device_t, void *); 117static void sbbrz_attach(device_t, device_t, void *);
118 118
119CFATTACH_DECL_NEW(sbbrz, 0, sbbrz_match, sbbrz_attach, NULL, NULL); 119CFATTACH_DECL_NEW(sbbrz, 0, sbbrz_match, sbbrz_attach, NULL, NULL);
120 120
121static int sbbrz_print(void *, const char *pnp); 121static int sbbrz_print(void *, const char *pnp);
122 122
123/* There can be only one. */ 123/* There can be only one. */
124struct sbbrz_softc sbbrz_softc; 124struct sbbrz_softc sbbrz_softc;
125 125
126static int 126static int
127sbbrz_match(device_t parent, cfdata_t match, void *aux) 127sbbrz_match(device_t parent, cfdata_t match, void *aux)
128{ 128{
129 struct zbbus_attach_args *zap = aux; 129 struct zbbus_attach_args *zap = aux;
130 130
131 if (zap->za_locs.za_type != ZBBUS_ENTTYPE_BRZ) 131 if (zap->za_locs.za_type != ZBBUS_ENTTYPE_BRZ)
132 return (0); 132 return (0);
133 133
134 if (sbbrz_softc.sc_dev != NULL) 134 if (sbbrz_softc.sc_dev != NULL)
135 return (0); 135 return (0);
136 136
137 return 1; 137 return 1;
138} 138}
139 139
140/* 140/*
141 * Set up the chipset's function pointers. 141 * Set up the chipset's function pointers.
142 */ 142 */
143static void 143static void
144sbbrz_init(struct sbbrz_softc *sc) 144sbbrz_init(struct sbbrz_softc *sc)
145{ 145{
146 int error; 146 int error;
147 147
148 sbbrz_bus_io_init(&sc->sc_iot, sc); 148 sbbrz_bus_io_init(&sc->sc_iot, sc);
149 sbbrz_bus_mem_init(&sc->sc_memt, sc); 149 sbbrz_bus_mem_init(&sc->sc_memt, sc);
150 150
151 bus_dma_tag_t t = &sc->sc_dmat64; 151 bus_dma_tag_t t = &sc->sc_dmat64;
152 t->_cookie = sc; 152 t->_cookie = sc;
153 t->_wbase = 0; 153 t->_wbase = 0;
154 t->_bounce_alloc_lo = 0; 154 t->_bounce_alloc_lo = 0;
155 t->_bounce_alloc_hi = 0; 155 t->_bounce_alloc_hi = 0;
156 t->_dmamap_ops = mips_bus_dmamap_ops; 156 t->_dmamap_ops = mips_bus_dmamap_ops;
157 t->_dmamem_ops = mips_bus_dmamem_ops; 157 t->_dmamem_ops = mips_bus_dmamem_ops;
158 t->_dmatag_ops = mips_bus_dmatag_ops; 158 t->_dmatag_ops = mips_bus_dmatag_ops;
159 159
160 error = bus_dmatag_subregion(t, 0, __MASK(32), &sc->sc_dmat32, 0); 160 error = bus_dmatag_subregion(t, 0, __MASK(32), &sc->sc_dmat32, 0);
161 if (error) 161 if (error)
162 panic("%s: failed to create 32bit dma tag: %d", 162 panic("%s: failed to create 32bit dma tag: %d",
163 __func__, error); 163 __func__, error);
164 164
165 sbbrz_pci_init(&sc->sc_pc, sc); 165 sbbrz_pci_init(&sc->sc_pc, sc);
166} 166}
167 167
168static void 168static void
169sbbrz_attach(device_t parent, device_t self, void *aux) 169sbbrz_attach(device_t parent, device_t self, void *aux)
170{ 170{
171 struct sbbrz_softc *sc = &sbbrz_softc; 171 struct sbbrz_softc *sc = &sbbrz_softc;
172 struct pcibus_attach_args pba; 172 struct pcibus_attach_args pba;
173 uint64_t regval; 173 uint64_t regval;
174 bool host; 174 bool host;
175 175
176 /* Tell the user whether it's host or device mode. */ 176 /* Tell the user whether it's host or device mode. */
177 regval = mips3_ld((register_t)MIPS_PHYS_TO_KSEG1(A_SCD_SYSTEM_CFG)); 177 regval = mips3_ld((register_t)MIPS_PHYS_TO_KSEG1(A_SCD_SYSTEM_CFG));
178 host = (regval & M_SYS_PCI_HOST) != 0; 178 host = (regval & M_SYS_PCI_HOST) != 0;
179 179
180 aprint_normal(": %s pci mode\n", host ? "host" : "device"); 180 aprint_normal(": %s pci mode\n", host ? "host" : "device");
181 181
182 /* note that we've attached the bridge; can't have two. */ 182 /* note that we've attached the bridge; can't have two. */
183 sc->sc_dev = self; 183 sc->sc_dev = self;
184 self->dv_private = sc; 184 device_set_private(self, sc);
185 185
186 /* 186 /*
187 * set up the bridge's info; done once at console init time 187 * set up the bridge's info; done once at console init time
188 * (maybe), but doesn't hurt to do twice. 188 * (maybe), but doesn't hurt to do twice.
189 */ 189 */
190 sbbrz_init(sc); 190 sbbrz_init(sc);
191 191
192#if _has_pba_busname 192#if _has_pba_busname
193 pba.pba_busname = "pci"; 193 pba.pba_busname = "pci";
194#endif 194#endif
195 pba.pba_iot = &sc->sc_iot; 195 pba.pba_iot = &sc->sc_iot;
196 pba.pba_memt = &sc->sc_memt; 196 pba.pba_memt = &sc->sc_memt;
197 pba.pba_dmat64 = &sc->sc_dmat64; 197 pba.pba_dmat64 = &sc->sc_dmat64;
198 pba.pba_dmat = sc->sc_dmat32; 198 pba.pba_dmat = sc->sc_dmat32;
199 pba.pba_pc = &sc->sc_pc; 199 pba.pba_pc = &sc->sc_pc;
200 pba.pba_bus = 0; 200 pba.pba_bus = 0;
201 pba.pba_bridgetag = NULL; 201 pba.pba_bridgetag = NULL;
202 pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY | 202 pba.pba_flags = PCI_FLAGS_IO_OKAY | PCI_FLAGS_MEM_OKAY |
203 PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY; 203 PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY;
204 config_found(self, &pba, sbbrz_print, CFARGS_NONE); 204 config_found(self, &pba, sbbrz_print, CFARGS_NONE);
205} 205}
206 206
207static int 207static int
208sbbrz_print(void *aux, const char *pnp) 208sbbrz_print(void *aux, const char *pnp)
209{ 209{
210 struct pcibus_attach_args *pba = aux; 210 struct pcibus_attach_args *pba = aux;
211 211
212 /* only PCIs can attach to sbbrz; easy. */ 212 /* only PCIs can attach to sbbrz; easy. */
213 if (pnp) 213 if (pnp)
214#if _has_pba_busname 214#if _has_pba_busname
215 aprint_normal("%s at %s\n", pba->pba_busname, pnp); 215 aprint_normal("%s at %s\n", pba->pba_busname, pnp);
216#else 216#else
217 aprint_normal("\n* sbbrz_pci at %s", pnp); 217 aprint_normal("\n* sbbrz_pci at %s", pnp);
218#endif 218#endif
219 aprint_normal(" bus %d", pba->pba_bus); 219 aprint_normal(" bus %d", pba->pba_bus);
220 return (UNCONF); 220 return (UNCONF);
221} 221}