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