3 * Hidetoshi Shimokawa. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
16 * This product includes software developed by Hidetoshi Shimokawa.
18 * 4. Neither the name of the author nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * $Id: dcons_crom.c,v 1.8 2003/10/23 15:47:21 simokawa Exp $
35 * $FreeBSD: src/sys/dev/dcons/dcons_crom.c,v 1.5 2004/10/13 05:38:42 simokawa Exp $
36 * $DragonFly: src/sys/dev/misc/dcons/dcons_crom.c,v 1.5 2006/12/22 23:26:17 swildner Exp $
39 #include <sys/param.h>
40 #include <sys/kernel.h>
41 #include <sys/module.h>
42 #include <sys/systm.h>
43 #include <sys/types.h>
45 #include <sys/malloc.h>
49 #include <bus/firewire/firewire.h>
50 #include <bus/firewire/firewirereg.h>
51 #include <bus/firewire/iec13213.h>
55 #include <dev/firewire/firewire.h>
56 #include <dev/firewire/firewirereg.h>
57 #include <dev/firewire/iec13213.h>
58 #include <dev/dcons/dcons.h>
59 #include <dev/dcons/dcons_os.h>
64 static bus_addr_t dcons_paddr;
66 #if __FreeBSD_version >= 500000
67 static int force_console = 1;
68 TUNABLE_INT("hw.firewire.dcons_crom.force_console", &force_console);
71 #ifndef CSRVAL_VENDOR_PRIVATE
72 #define NEED_NEW_DRIVER
75 #define ADDR_HI(x) (((x) >> 24) & 0xffffff)
76 #define ADDR_LO(x) ((x) & 0xffffff)
78 struct dcons_crom_softc {
79 struct firewire_dev_comm fd;
80 struct crom_chunk unit;
81 struct crom_chunk spec;
82 struct crom_chunk ver;
83 bus_dma_tag_t dma_tag;
89 dcons_crom_probe(device_t dev)
93 pa = device_get_parent(dev);
94 if(device_get_unit(dev) != device_get_unit(pa)){
98 device_set_desc(dev, "dcons configuration ROM");
102 #ifndef NEED_NEW_DRIVER
104 dcons_crom_post_busreset(void *arg)
106 struct dcons_crom_softc *sc;
107 struct crom_src *src;
108 struct crom_chunk *root;
110 sc = (struct dcons_crom_softc *) arg;
111 src = sc->fd.fc->crom_src;
112 root = sc->fd.fc->crom_root;
114 bzero(&sc->unit, sizeof(struct crom_chunk));
116 crom_add_chunk(src, root, &sc->unit, CROM_UDIR);
117 crom_add_entry(&sc->unit, CSRKEY_SPEC, CSRVAL_VENDOR_PRIVATE);
118 crom_add_simple_text(src, &sc->unit, &sc->spec, "FreeBSD");
119 crom_add_entry(&sc->unit, CSRKEY_VER, DCONS_CSR_VAL_VER);
120 crom_add_simple_text(src, &sc->unit, &sc->ver, "dcons");
121 crom_add_entry(&sc->unit, DCONS_CSR_KEY_HI, ADDR_HI(dcons_paddr));
122 crom_add_entry(&sc->unit, DCONS_CSR_KEY_LO, ADDR_LO(dcons_paddr));
127 dmamap_cb(void *arg, bus_dma_segment_t *segments, int seg, int error)
129 struct dcons_crom_softc *sc;
132 kprintf("dcons_dmamap_cb: error=%d\n", error);
134 sc = (struct dcons_crom_softc *)arg;
135 sc->bus_addr = segments[0].ds_addr;
137 bus_dmamap_sync(sc->dma_tag, sc->dma_map, BUS_DMASYNC_PREWRITE);
138 device_printf(sc->fd.dev, "bus_addr 0x%jx\n",
139 (uintmax_t)sc->bus_addr);
140 if (dcons_paddr != 0) {
142 device_printf(sc->fd.dev, "dcons_paddr is already set\n");
145 dcons_conf->dma_tag = sc->dma_tag;
146 dcons_conf->dma_map = sc->dma_map;
147 dcons_paddr = sc->bus_addr;
149 #if __FreeBSD_version >= 500000
150 /* Force to be the high-level console */
152 cnselect(dcons_conf->cdev);
157 dcons_crom_attach(device_t dev)
159 #ifdef NEED_NEW_DRIVER
160 kprintf("dcons_crom: you need newer firewire driver\n");
163 struct dcons_crom_softc *sc;
165 sc = (struct dcons_crom_softc *) device_get_softc(dev);
166 sc->fd.fc = device_get_ivars(dev);
168 sc->fd.post_explore = NULL;
169 sc->fd.post_busreset = (void *) dcons_crom_post_busreset;
171 /* map dcons buffer */
173 /*parent*/ sc->fd.fc->dmat,
174 /*alignment*/ sizeof(u_int32_t),
176 /*lowaddr*/ BUS_SPACE_MAXADDR,
177 /*highaddr*/ BUS_SPACE_MAXADDR,
178 /*filter*/NULL, /*filterarg*/NULL,
179 /*maxsize*/ dcons_conf->size,
181 /*maxsegsz*/ BUS_SPACE_MAXSIZE_32BIT,
182 /*flags*/ BUS_DMA_ALLOCNOW,
183 #if __FreeBSD_version >= 501102
184 /*lockfunc*/busdma_lock_mutex,
188 bus_dmamap_create(sc->dma_tag, 0, &sc->dma_map);
189 bus_dmamap_load(sc->dma_tag, sc->dma_map,
190 (void *)dcons_conf->buf, dcons_conf->size,
197 dcons_crom_detach(device_t dev)
199 struct dcons_crom_softc *sc;
201 sc = (struct dcons_crom_softc *) device_get_softc(dev);
202 sc->fd.post_busreset = NULL;
205 if (dcons_conf->dma_tag == sc->dma_tag)
206 dcons_conf->dma_tag = NULL;
208 bus_dmamap_unload(sc->dma_tag, sc->dma_map);
209 bus_dmamap_destroy(sc->dma_tag, sc->dma_map);
210 bus_dma_tag_destroy(sc->dma_tag);
216 * Because dcons_crom is a static device that always exists under any attached
217 * firewire device, and not scanned by the firewire device, we need an
218 * identify function to install the device. For our sanity we want
219 * the sbp device to have the same unit number as the fireweire device.
221 static devclass_t dcons_crom_devclass;
223 static device_method_t dcons_crom_methods[] = {
224 /* device interface */
225 DEVMETHOD(device_identify, bus_generic_identify_sameunit),
226 DEVMETHOD(device_probe, dcons_crom_probe),
227 DEVMETHOD(device_attach, dcons_crom_attach),
228 DEVMETHOD(device_detach, dcons_crom_detach),
232 static driver_t dcons_crom_driver = {
235 sizeof(struct dcons_crom_softc),
238 DRIVER_MODULE(dcons_crom, firewire, dcons_crom_driver,
239 dcons_crom_devclass, 0, 0);
240 MODULE_VERSION(dcons_crom, 1);
241 MODULE_DEPEND(dcons_crom, dcons,
242 DCONS_VERSION, DCONS_VERSION, DCONS_VERSION);
243 MODULE_DEPEND(dcons_crom, firewire, 1, 1, 1);