tft_plb.c revision 1.1.6.2 1 1.1.6.2 ad /* $NetBSD: tft_plb.c,v 1.1.6.2 2007/01/12 01:00:47 ad Exp $ */
2 1.1.6.2 ad
3 1.1.6.2 ad /*
4 1.1.6.2 ad * Copyright (c) 2006 Jachym Holecek
5 1.1.6.2 ad * All rights reserved.
6 1.1.6.2 ad *
7 1.1.6.2 ad * Written for DFC Design, s.r.o.
8 1.1.6.2 ad *
9 1.1.6.2 ad * Redistribution and use in source and binary forms, with or without
10 1.1.6.2 ad * modification, are permitted provided that the following conditions
11 1.1.6.2 ad * are met:
12 1.1.6.2 ad *
13 1.1.6.2 ad * 1. Redistributions of source code must retain the above copyright
14 1.1.6.2 ad * notice, this list of conditions and the following disclaimer.
15 1.1.6.2 ad *
16 1.1.6.2 ad * 2. Redistributions in binary form must reproduce the above copyright
17 1.1.6.2 ad * notice, this list of conditions and the following disclaimer in the
18 1.1.6.2 ad * documentation and/or other materials provided with the distribution.
19 1.1.6.2 ad *
20 1.1.6.2 ad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1.6.2 ad * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1.6.2 ad * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1.6.2 ad * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1.6.2 ad * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1.6.2 ad * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1.6.2 ad * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1.6.2 ad * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1.6.2 ad * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1.6.2 ad * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1.6.2 ad */
31 1.1.6.2 ad
32 1.1.6.2 ad #include <sys/cdefs.h>
33 1.1.6.2 ad __KERNEL_RCSID(0, "$NetBSD: tft_plb.c,v 1.1.6.2 2007/01/12 01:00:47 ad Exp $");
34 1.1.6.2 ad
35 1.1.6.2 ad #include <sys/param.h>
36 1.1.6.2 ad #include <sys/systm.h>
37 1.1.6.2 ad #include <sys/mbuf.h>
38 1.1.6.2 ad #include <sys/kernel.h>
39 1.1.6.2 ad #include <sys/socket.h>
40 1.1.6.2 ad #include <sys/ioctl.h>
41 1.1.6.2 ad #include <sys/device.h>
42 1.1.6.2 ad #include <sys/queue.h>
43 1.1.6.2 ad
44 1.1.6.2 ad #include <uvm/uvm_extern.h>
45 1.1.6.2 ad
46 1.1.6.2 ad #include <machine/bus.h>
47 1.1.6.2 ad
48 1.1.6.2 ad #include <dev/wscons/wsdisplayvar.h>
49 1.1.6.2 ad #include <dev/wscons/wsconsio.h>
50 1.1.6.2 ad #include <dev/rasops/rasops.h>
51 1.1.6.2 ad #include <dev/wscons/wsdisplay_vconsvar.h>
52 1.1.6.2 ad
53 1.1.6.2 ad #include <evbppc/virtex/dev/xcvbusvar.h>
54 1.1.6.2 ad #include <evbppc/virtex/dev/tftreg.h>
55 1.1.6.2 ad #include <evbppc/virtex/dev/tftvar.h>
56 1.1.6.2 ad
57 1.1.6.2 ad
58 1.1.6.2 ad struct plb_tft_softc {
59 1.1.6.2 ad struct tft_softc psc_sc;
60 1.1.6.2 ad
61 1.1.6.2 ad bus_dma_tag_t psc_dmat;
62 1.1.6.2 ad bus_dmamap_t psc_dmap; /* for psc_sc.sc_image */
63 1.1.6.2 ad bus_dma_segment_t psc_seg;
64 1.1.6.2 ad
65 1.1.6.2 ad void *sc_sdhook; /* stop DMA */
66 1.1.6.2 ad };
67 1.1.6.2 ad
68 1.1.6.2 ad static void plb_tft_attach(struct device *, struct device *, void *);
69 1.1.6.2 ad static paddr_t plb_tft_mmap(void *, void *, off_t, int);
70 1.1.6.2 ad
71 1.1.6.2 ad CFATTACH_DECL(plb_tft, sizeof(struct plb_tft_softc),
72 1.1.6.2 ad xcvbus_child_match, plb_tft_attach, NULL, NULL);
73 1.1.6.2 ad
74 1.1.6.2 ad
75 1.1.6.2 ad /* Patched by tft_attach(), may be shared by all instances. */
76 1.1.6.2 ad static struct wsdisplay_accessops plb_tft_accessops = {
77 1.1.6.2 ad .mmap = plb_tft_mmap,
78 1.1.6.2 ad };
79 1.1.6.2 ad
80 1.1.6.2 ad
81 1.1.6.2 ad /*
82 1.1.6.2 ad * Generic device.
83 1.1.6.2 ad */
84 1.1.6.2 ad static void
85 1.1.6.2 ad plb_tft_attach(struct device *parent, struct device *self, void *aux)
86 1.1.6.2 ad {
87 1.1.6.2 ad struct xcvbus_attach_args *vaa = aux;
88 1.1.6.2 ad struct plb_tft_softc *psc = device_private(self);
89 1.1.6.2 ad struct tft_softc *sc = &psc->psc_sc;
90 1.1.6.2 ad int nseg, error;
91 1.1.6.2 ad
92 1.1.6.2 ad psc->psc_dmat = vaa->vaa_dmat;
93 1.1.6.2 ad sc->sc_iot = vaa->vaa_iot;
94 1.1.6.2 ad
95 1.1.6.2 ad printf(": PLB_TFT\n");
96 1.1.6.2 ad
97 1.1.6.2 ad if ((error = bus_space_map(sc->sc_iot, vaa->vaa_addr, TFT_SIZE,
98 1.1.6.2 ad 0, &sc->sc_ioh)) != 0) {
99 1.1.6.2 ad printf("%s: could not map device registers\n",
100 1.1.6.2 ad device_xname(self));
101 1.1.6.2 ad goto fail_0;
102 1.1.6.2 ad }
103 1.1.6.2 ad
104 1.1.6.2 ad /* Fill in resolution, depth, size. */
105 1.1.6.2 ad tft_mode(self);
106 1.1.6.2 ad
107 1.1.6.2 ad /* Allocate and map framebuffer control data. */
108 1.1.6.2 ad if ((error = bus_dmamem_alloc(psc->psc_dmat, sc->sc_size, ADDR_ALIGN,
109 1.1.6.2 ad 0, &psc->psc_seg, 1, &nseg, 0)) != 0) {
110 1.1.6.2 ad printf("%s: could not allocate framebuffer\n",
111 1.1.6.2 ad device_xname(self));
112 1.1.6.2 ad goto fail_1;
113 1.1.6.2 ad }
114 1.1.6.2 ad if ((error = bus_dmamem_map(psc->psc_dmat, &psc->psc_seg, nseg,
115 1.1.6.2 ad sc->sc_size, &sc->sc_image, BUS_DMA_COHERENT)) != 0) {
116 1.1.6.2 ad printf("%s: could not map framebuffer\n",
117 1.1.6.2 ad device_xname(self));
118 1.1.6.2 ad goto fail_2;
119 1.1.6.2 ad }
120 1.1.6.2 ad if ((error = bus_dmamap_create(psc->psc_dmat, sc->sc_size, 1,
121 1.1.6.2 ad sc->sc_size, 0, 0, &psc->psc_dmap)) != 0) {
122 1.1.6.2 ad printf("%s: could not create framebuffer DMA map\n",
123 1.1.6.2 ad device_xname(self));
124 1.1.6.2 ad goto fail_3;
125 1.1.6.2 ad }
126 1.1.6.2 ad if ((error = bus_dmamap_load(psc->psc_dmat, psc->psc_dmap,
127 1.1.6.2 ad sc->sc_image, sc->sc_size, NULL, 0)) != 0) {
128 1.1.6.2 ad printf("%s: could not load framebuffer DMA map\n",
129 1.1.6.2 ad device_xname(self));
130 1.1.6.2 ad goto fail_4;
131 1.1.6.2 ad }
132 1.1.6.2 ad /* XXX hack, we linear map whole RAM and we have single segment */
133 1.1.6.2 ad /* sc->sc_image = (caddr_t)psc->psc_dmap->dm_segs[0].ds_addr; */
134 1.1.6.2 ad /* XXX hack, use predefined base addr */
135 1.1.6.2 ad sc->sc_image = (caddr_t)(uintptr_t)0x3c00000;
136 1.1.6.2 ad
137 1.1.6.2 ad /* XXX fuck the hack above, use "virtex-tft-framebuffer-base" prop */
138 1.1.6.2 ad
139 1.1.6.2 ad tft_attach(self, &plb_tft_accessops);
140 1.1.6.2 ad
141 1.1.6.2 ad printf("%s: video memory pa 0x%08x\n", device_xname(self),
142 1.1.6.2 ad (uint32_t)psc->psc_dmap->dm_segs[0].ds_addr);
143 1.1.6.2 ad
144 1.1.6.2 ad #if 0
145 1.1.6.2 ad /* XXX powerpc bus_dma doesn't support COHERENT. */
146 1.1.6.2 ad bus_dmamap_sync(psc->psc_dmat, psc->psc_dmap, 0,
147 1.1.6.2 ad sc->sc_size, BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
148 1.1.6.2 ad #endif
149 1.1.6.2 ad
150 1.1.6.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, TFT_CTRL, CTRL_RESET);
151 1.1.6.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, TFT_CTRL, CTRL_ENABLE);
152 1.1.6.2 ad
153 1.1.6.2 ad #if 0
154 1.1.6.2 ad /* XXX how the fuck do we change framebuffer base? */
155 1.1.6.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, TFT_CTRL, CTRL_RESET);
156 1.1.6.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, TFT_CTRL, CTRL_ENABLE);
157 1.1.6.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, TFT_ADDR,
158 1.1.6.2 ad ADDR_MAKE(psc->psc_dmap->dm_segs[0].ds_addr));
159 1.1.6.2 ad #endif
160 1.1.6.2 ad
161 1.1.6.2 ad return ;
162 1.1.6.2 ad
163 1.1.6.2 ad fail_4:
164 1.1.6.2 ad bus_dmamap_destroy(psc->psc_dmat, psc->psc_dmap);
165 1.1.6.2 ad fail_3:
166 1.1.6.2 ad bus_dmamem_unmap(psc->psc_dmat, sc->sc_image, sc->sc_size);
167 1.1.6.2 ad fail_2:
168 1.1.6.2 ad bus_dmamem_free(psc->psc_dmat, &psc->psc_seg, nseg);
169 1.1.6.2 ad fail_1:
170 1.1.6.2 ad bus_space_unmap(sc->sc_iot, sc->sc_ioh, TFT_SIZE);
171 1.1.6.2 ad fail_0:
172 1.1.6.2 ad printf("%s: error %d\n", device_xname(self), error);
173 1.1.6.2 ad }
174 1.1.6.2 ad
175 1.1.6.2 ad static paddr_t
176 1.1.6.2 ad plb_tft_mmap(void *arg, void *scr, off_t offs, int prot)
177 1.1.6.2 ad {
178 1.1.6.2 ad struct vcons_data *vc = arg;
179 1.1.6.2 ad struct plb_tft_softc *psc = vc->cookie;
180 1.1.6.2 ad paddr_t pa = -1;
181 1.1.6.2 ad
182 1.1.6.2 ad #if 0 /* XXX hack */
183 1.1.6.2 ad if (offs < psc->psc_sc.sc_size)
184 1.1.6.2 ad pa = bus_dmamem_mmap(psc->psc_dmat, &psc->psc_seg, 1,
185 1.1.6.2 ad offs, prot, BUS_DMA_WAITOK | BUS_DMA_COHERENT);
186 1.1.6.2 ad #endif
187 1.1.6.2 ad if (offs < psc->psc_sc.sc_size)
188 1.1.6.2 ad pa = (paddr_t)(intptr_t)psc->psc_sc.sc_image + offs;
189 1.1.6.2 ad
190 1.1.6.2 ad return (pa);
191 1.1.6.2 ad }
192