]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/mips/broadcom/bcma_nexus.c
MFV r331400: 8484 Implement aggregate sum and use for arc counters
[FreeBSD/FreeBSD.git] / sys / mips / broadcom / bcma_nexus.c
1 /*-
2  * Copyright (c) 2016 Michael Zhilin <mizhka@gmail.com>
3  * Copyright (c) 2015-2016 Landon Fuller <landon@freebsd.org>
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer,
11  *    without modification.
12  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
13  *    similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
14  *    redistribution must be conditioned upon including a substantially
15  *    similar Disclaimer requirement for further binary redistribution.
16  *
17  * NO WARRANTY
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
21  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22  * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
23  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
26  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28  * THE POSSIBILITY OF SUCH DAMAGES.
29  * 
30  * $FreeBSD$
31  */
32
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
35
36 #include <sys/param.h>
37 #include <sys/kernel.h>
38 #include <sys/bus.h>
39 #include <sys/module.h>
40
41 #include <machine/bus.h>
42 #include <sys/rman.h>
43 #include <machine/resource.h>
44
45 #include <dev/bhnd/bhnd_ids.h>
46
47 #include <dev/bhnd/bcma/bcmavar.h>
48 #include <dev/bhnd/bcma/bcma_dmp.h>
49
50 #include "bcm_mipsvar.h"
51 #include "bcm_machdep.h"
52
53 #include "bhnd_nexusvar.h"
54
55 /*
56  * Supports bcma(4) attachment to a MIPS nexus bus.
57  */
58
59 static int      bcma_nexus_attach(device_t);
60 static int      bcma_nexus_probe(device_t);
61
62 _Static_assert(BCMA_OOB_NUM_BUSLINES == BCM_MIPS_NINTR, "BCMA incompatible "
63     "with generic NINTR");
64
65 static int
66 bcma_nexus_probe(device_t dev)
67 {
68         int error;
69
70         switch (bcm_get_platform()->cid.chip_type) {
71         case BHND_CHIPTYPE_BCMA:
72         case BHND_CHIPTYPE_BCMA_ALT:
73         case BHND_CHIPTYPE_UBUS:
74                 break;
75         default:
76                 return (ENXIO);
77         }
78
79         if ((error = bcma_probe(dev)) > 0)
80                 return (error);
81
82         /* Set device description */
83         bhnd_set_default_bus_desc(dev, &bcm_get_platform()->cid);
84
85         return (BUS_PROBE_SPECIFIC);
86 }
87
88 static int
89 bcma_nexus_attach(device_t dev)
90 {
91         int error;
92
93         /* Perform initial attach and enumerate our children. */
94         if ((error = bcma_attach(dev)))
95                 goto failed;
96
97         /* Delegate remainder to standard bhnd method implementation */
98         if ((error = bhnd_generic_attach(dev)))
99                 goto failed;
100
101         return (0);
102
103 failed:
104         device_delete_children(dev);
105         return (error);
106 }
107
108 static device_method_t bcma_nexus_methods[] = {
109         DEVMETHOD(device_probe,                 bcma_nexus_probe),
110         DEVMETHOD(device_attach,                bcma_nexus_attach),
111
112         DEVMETHOD_END
113 };
114
115 DEFINE_CLASS_2(bhnd, bcma_nexus_driver, bcma_nexus_methods,
116     sizeof(struct bcma_softc), bhnd_nexus_driver, bcma_driver);
117
118 EARLY_DRIVER_MODULE(bcma_nexus, nexus, bcma_nexus_driver, bhnd_devclass, 0, 0,
119     BUS_PASS_BUS + BUS_PASS_ORDER_MIDDLE);