exb.c revision 1.2.8.2 1 1.2.8.2 rmind /* $Id: exb.c,v 1.2.8.2 2011/03/05 20:51:36 rmind Exp $ */
2 1.2.8.2 rmind
3 1.2.8.2 rmind /*-
4 1.2.8.2 rmind * Copyright (c) 2010 The NetBSD Foundation, Inc.
5 1.2.8.2 rmind * All rights reserved.
6 1.2.8.2 rmind *
7 1.2.8.2 rmind * This code is derived from software developed for The NetBSD Foundation
8 1.2.8.2 rmind * by Masao Uebayashi.
9 1.2.8.2 rmind *
10 1.2.8.2 rmind * Redistribution and use in source and binary forms, with or without
11 1.2.8.2 rmind * modification, are permitted provided that the following conditions
12 1.2.8.2 rmind * are met:
13 1.2.8.2 rmind * 1. Redistributions of source code must retain the above copyright
14 1.2.8.2 rmind * notice, this list of conditions and the following disclaimer.
15 1.2.8.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.8.2 rmind * notice, this list of conditions and the following disclaimer in the
17 1.2.8.2 rmind * documentation and/or other materials provided with the distribution.
18 1.2.8.2 rmind *
19 1.2.8.2 rmind * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.2.8.2 rmind * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.2.8.2 rmind * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.2.8.2 rmind * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.2.8.2 rmind * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.2.8.2 rmind * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.2.8.2 rmind * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.2.8.2 rmind * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.2.8.2 rmind * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.2.8.2 rmind * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.2.8.2 rmind * POSSIBILITY OF SUCH DAMAGE.
30 1.2.8.2 rmind */
31 1.2.8.2 rmind
32 1.2.8.2 rmind #include <sys/cdefs.h>
33 1.2.8.2 rmind __KERNEL_RCSID(0, "$NetBSD: exb.c,v 1.2.8.2 2011/03/05 20:51:36 rmind Exp $");
34 1.2.8.2 rmind
35 1.2.8.2 rmind #include "locators.h"
36 1.2.8.2 rmind
37 1.2.8.2 rmind #include <sys/param.h>
38 1.2.8.2 rmind #include <sys/systm.h>
39 1.2.8.2 rmind #include <sys/device.h>
40 1.2.8.2 rmind #include <sys/extent.h>
41 1.2.8.2 rmind #include <sys/bus.h>
42 1.2.8.2 rmind
43 1.2.8.2 rmind #include <powerpc/ibm4xx/dcr4xx.h>
44 1.2.8.2 rmind #include <powerpc/ibm4xx/dev/exbvar.h>
45 1.2.8.2 rmind
46 1.2.8.2 rmind struct exb_softc {
47 1.2.8.2 rmind };
48 1.2.8.2 rmind
49 1.2.8.2 rmind extern const struct exb_conf exb_confs[];
50 1.2.8.2 rmind
51 1.2.8.2 rmind static int exb_match(device_t, struct cfdata *, void *);
52 1.2.8.2 rmind static void exb_attach(device_t, struct device *, void *);
53 1.2.8.2 rmind static int exb_print(void *, const char *);
54 1.2.8.2 rmind
55 1.2.8.2 rmind CFATTACH_DECL_NEW(exb, sizeof(struct exb_softc), exb_match, exb_attach,
56 1.2.8.2 rmind NULL, NULL);
57 1.2.8.2 rmind
58 1.2.8.2 rmind static struct powerpc_bus_space exb_bus_space_tag =
59 1.2.8.2 rmind { _BUS_SPACE_BIG_ENDIAN | _BUS_SPACE_MEM_TYPE, 0 };
60 1.2.8.2 rmind
61 1.2.8.2 rmind static int
62 1.2.8.2 rmind exb_match(device_t parent, struct cfdata *cf, void *aux)
63 1.2.8.2 rmind {
64 1.2.8.2 rmind
65 1.2.8.2 rmind return 1;
66 1.2.8.2 rmind }
67 1.2.8.2 rmind
68 1.2.8.2 rmind static void
69 1.2.8.2 rmind exb_attach(device_t parent, device_t self, void *aux)
70 1.2.8.2 rmind {
71 1.2.8.2 rmind const struct exb_conf *ec = exb_confs;
72 1.2.8.2 rmind uint32_t ebc0_bNcr;
73 1.2.8.2 rmind bus_addr_t base, size;
74 1.2.8.2 rmind int locs[EXBCF_NLOCS];
75 1.2.8.2 rmind
76 1.2.8.2 rmind printf("\n");
77 1.2.8.2 rmind
78 1.2.8.2 rmind /* mtdcr needs a constant */
79 1.2.8.2 rmind switch (device_unit(self)) {
80 1.2.8.2 rmind case 0: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B0CR); break;
81 1.2.8.2 rmind case 1: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B1CR); break;
82 1.2.8.2 rmind case 2: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B2CR); break;
83 1.2.8.2 rmind case 3: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B3CR); break;
84 1.2.8.2 rmind case 4: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B4CR); break;
85 1.2.8.2 rmind case 5: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B5CR); break;
86 1.2.8.2 rmind case 6: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B6CR); break;
87 1.2.8.2 rmind case 7: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B7CR); break;
88 1.2.8.2 rmind }
89 1.2.8.2 rmind ebc0_bNcr = mfdcr(DCR_EBC0_CFGDATA);
90 1.2.8.2 rmind base = ebc0_bNcr & 0xfff00000;
91 1.2.8.2 rmind size = 0x00100000 << ((ebc0_bNcr & 0x000e0000) >> 17);
92 1.2.8.2 rmind
93 1.2.8.2 rmind exb_bus_space_tag.pbs_base = base;
94 1.2.8.2 rmind exb_bus_space_tag.pbs_limit = base + size - 1;
95 1.2.8.2 rmind
96 1.2.8.2 rmind while (ec->ec_name) {
97 1.2.8.2 rmind struct exb_conf ec1;
98 1.2.8.2 rmind
99 1.2.8.2 rmind locs[EXBCF_ADDR] = ec->ec_addr;
100 1.2.8.2 rmind
101 1.2.8.2 rmind ec1 = *ec;
102 1.2.8.2 rmind ec1.ec_bust = exb_get_bus_space_tag();
103 1.2.8.2 rmind
104 1.2.8.2 rmind config_found_sm_loc(self, "exb", locs, &ec1, exb_print,
105 1.2.8.2 rmind config_stdsubmatch);
106 1.2.8.2 rmind ec++;
107 1.2.8.2 rmind }
108 1.2.8.2 rmind }
109 1.2.8.2 rmind
110 1.2.8.2 rmind static int
111 1.2.8.2 rmind exb_print(void *aux, const char *bus)
112 1.2.8.2 rmind {
113 1.2.8.2 rmind struct exb_conf *ec = aux;
114 1.2.8.2 rmind
115 1.2.8.2 rmind if (bus)
116 1.2.8.2 rmind return QUIET;
117 1.2.8.2 rmind
118 1.2.8.2 rmind if (ec->ec_addr)
119 1.2.8.2 rmind printf(" addr %"PRIxBUSADDR, ec->ec_addr);
120 1.2.8.2 rmind
121 1.2.8.2 rmind return UNCONF;
122 1.2.8.2 rmind }
123 1.2.8.2 rmind
124 1.2.8.2 rmind bus_space_tag_t
125 1.2.8.2 rmind exb_get_bus_space_tag(void)
126 1.2.8.2 rmind {
127 1.2.8.2 rmind static char ex_storage[EXTENT_FIXED_STORAGE_SIZE(8)]
128 1.2.8.2 rmind __attribute__((aligned(8)));
129 1.2.8.2 rmind static int exb_bus_space_tag_inited;
130 1.2.8.2 rmind
131 1.2.8.2 rmind if (exb_bus_space_tag_inited == 0) {
132 1.2.8.2 rmind if (bus_space_init(&exb_bus_space_tag, "exbtag",
133 1.2.8.2 rmind ex_storage, sizeof(ex_storage)))
134 1.2.8.2 rmind panic("exb_attach: Failed to initialise exb_bus_space_tag");
135 1.2.8.2 rmind exb_bus_space_tag_inited = 1;
136 1.2.8.2 rmind }
137 1.2.8.2 rmind return &exb_bus_space_tag;
138 1.2.8.2 rmind }
139