1 /* $NetBSD: design_gsrd2.c,v 1.2.12.1 2007/05/28 20:01:42 freza Exp $ */
4 * Copyright (c) 2006 Jachym Holecek
7 * Written for DFC Design, s.r.o.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "opt_virtex.h"
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: design_gsrd2.c,v 1.2.12.1 2007/05/28 20:01:42 freza Exp $");
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/device.h>
40 #include <sys/kernel.h>
41 #include <sys/malloc.h>
42 #include <sys/extent.h>
44 #include <machine/cpu.h>
45 #include <machine/bus.h>
46 #include <machine/intr.h>
47 #include <machine/powerpc.h>
48 #include <machine/tlb.h>
50 #include <powerpc/ibm4xx/dev/plbvar.h>
52 #include <evbppc/virtex/dev/xcvbusvar.h>
53 #include <evbppc/virtex/dev/cdmacreg.h>
54 #include <evbppc/virtex/dev/temacreg.h>
55 #include <evbppc/virtex/dev/tftreg.h>
57 #include <evbppc/virtex/virtex.h>
58 #include <evbppc/virtex/dcr.h>
61 #define DCR_TEMAC_BASE 0x0030
62 #define DCR_TFT0_BASE 0x0082
63 #define DCR_TFT1_BASE 0x0086
64 #define DCR_CDMAC_BASE 0x0140
66 #define OPB_BASE 0x80000000 /* below are offsets in opb */
67 #define OPB_XLCOM_BASE 0x010000
68 #define OPB_GPIO_BASE 0x020000
69 #define OPB_PSTWO0_BASE 0x040000
70 #define OPB_PSTWO1_BASE 0x041000
71 #define CDMAC_NCHAN 2 /* cdmac {Tx,Rx} */
72 #define CDMAC_INTR_LINE 0
74 #define TFT_FB_BASE 0x3c00000
75 #define TFT_FB_SIZE (2*1024*1024)
78 * CDMAC per-channel interrupt handler. CDMAC has one interrupt signal
79 * per two channels on mpmc2, so we have to dispatch channels manually.
81 * Note: we hardwire priority to IPL_NET, temac(4) is the only device that
82 * needs to service DMA interrupts anyway.
84 typedef struct cdmac_intrhand
{
85 void (*cih_func
)(void *);
89 /* Two instantiated channels, one logical interrupt per direction. */
90 static struct cdmac_intrhand cdmacintr
[CDMAC_NCHAN
];
91 static void *cdmac_ih
;
95 * DCR bus space leaf access routines.
99 tft0_write_4(bus_space_tag_t t
, bus_space_handle_t h
, uint32_t addr
,
105 WCASE(DCR_TFT0_BASE
, TFT_CTRL
);
106 WCASE(DCR_TFT0_BASE
, TFT_ADDR
);
112 tft0_read_4(bus_space_tag_t t
, bus_space_handle_t h
, uint32_t addr
)
119 RCASE(DCR_TFT0_BASE
, TFT_CTRL
);
120 RCASE(DCR_TFT0_BASE
, TFT_ADDR
);
128 tft1_write_4(bus_space_tag_t t
, bus_space_handle_t h
, uint32_t addr
,
134 WCASE(DCR_TFT1_BASE
, TFT_CTRL
);
135 WCASE(DCR_TFT0_BASE
, TFT_ADDR
);
141 tft1_read_4(bus_space_tag_t t
, bus_space_handle_t h
, uint32_t addr
)
148 RCASE(DCR_TFT1_BASE
, TFT_CTRL
);
149 RCASE(DCR_TFT0_BASE
, TFT_ADDR
);
156 #define DOCHAN(op, base, channel) \
157 op(base, channel + CDMAC_NEXT); \
158 op(base, channel + CDMAC_CURADDR); \
159 op(base, channel + CDMAC_CURSIZE); \
160 op(base, channel + CDMAC_CURDESC)
163 cdmac_write_4(bus_space_tag_t t
, bus_space_handle_t h
, uint32_t addr
,
169 WCASE(DCR_CDMAC_BASE
, CDMAC_STAT_BASE(0)); /* Tx engine */
170 WCASE(DCR_CDMAC_BASE
, CDMAC_STAT_BASE(1)); /* Rx engine */
171 WCASE(DCR_CDMAC_BASE
, CDMAC_INTR
);
172 DOCHAN(WCASE
, DCR_CDMAC_BASE
, CDMAC_CTRL_BASE(0));
173 DOCHAN(WCASE
, DCR_CDMAC_BASE
, CDMAC_CTRL_BASE(1));
179 cdmac_read_4(bus_space_tag_t t
, bus_space_handle_t h
, uint32_t addr
)
186 RCASE(DCR_CDMAC_BASE
, CDMAC_STAT_BASE(0)); /* Tx engine */
187 RCASE(DCR_CDMAC_BASE
, CDMAC_STAT_BASE(1)); /* Rx engine */
188 RCASE(DCR_CDMAC_BASE
, CDMAC_INTR
);
189 DOCHAN(RCASE
, DCR_CDMAC_BASE
, CDMAC_CTRL_BASE(0));
190 DOCHAN(RCASE
, DCR_CDMAC_BASE
, CDMAC_CTRL_BASE(1));
200 temac_write_4(bus_space_tag_t t
, bus_space_handle_t h
, uint32_t addr
,
206 WCASE(DCR_TEMAC_BASE
, TEMAC_RESET
);
212 temac_read_4(bus_space_tag_t t
, bus_space_handle_t h
, uint32_t addr
)
219 RCASE(DCR_TEMAC_BASE
, TEMAC_RESET
);
226 static const struct powerpc_bus_space cdmac_bst
= {
227 DCR_BST_BODY(DCR_CDMAC_BASE
, cdmac_read_4
, cdmac_write_4
)
230 static const struct powerpc_bus_space temac_bst
= {
231 DCR_BST_BODY(DCR_TEMAC_BASE
, temac_read_4
, temac_write_4
)
234 static const struct powerpc_bus_space tft0_bst
= {
235 DCR_BST_BODY(DCR_TFT0_BASE
, tft0_read_4
, tft0_write_4
)
238 static const struct powerpc_bus_space tft1_bst
= {
239 DCR_BST_BODY(DCR_TFT1_BASE
, tft1_read_4
, tft1_write_4
)
242 static struct powerpc_bus_space opb_bst
= {
243 .pbs_flags
= _BUS_SPACE_BIG_ENDIAN
|_BUS_SPACE_MEM_TYPE
,
244 .pbs_base
= 0 /*OPB_BASE*/,
245 .pbs_offset
= OPB_BASE
,
248 static char opb_extent_storage
[EXTENT_FIXED_STORAGE_SIZE(8)] __aligned(8);
251 * Master device configuration table for GSRD2 design.
253 static const struct gsrddev
{
254 const char *gdv_name
;
255 const char *gdv_attr
;
256 bus_space_tag_t gdv_bst
;
261 int gdv_dcr
; /* XXX bst flag */
263 { /* gsrd_devices[0] */
265 .gdv_attr
= "xcvbus",
267 .gdv_addr
= OPB_XLCOM_BASE
,
273 { /* gsrd_devices[1] */
275 .gdv_attr
= "xcvbus",
276 .gdv_bst
= &temac_bst
,
278 .gdv_intr
= 1, /* unused MII intr */
279 .gdv_rx_dma
= 1, /* cdmac Rx */
280 .gdv_tx_dma
= 0, /* cdmac Tx */
284 { /* gsrd_devices[2] */
287 .gdv_bst
= &tft0_bst
,
295 { /* gsrd_devices[2] */
298 .gdv_bst
= &tft1_bst
,
306 { /* gsrd_devices[3] */
308 .gdv_attr
= "xcvbus",
310 .gdv_addr
= OPB_PSTWO0_BASE
,
316 { /* gsrd_devices[4] */
318 .gdv_attr
= "xcvbus",
320 .gdv_addr
= OPB_PSTWO1_BASE
,
329 static struct ll_dmac
*
330 virtex_mpmc_mapdma(int idx
, struct ll_dmac
*chan
)
335 KASSERT(idx
>= 0 && idx
< CDMAC_NCHAN
);
337 chan
->dmac_iot
= &cdmac_bst
;
338 chan
->dmac_ctrl_addr
= CDMAC_CTRL_BASE(idx
);
339 chan
->dmac_stat_addr
= CDMAC_STAT_BASE(idx
);
340 chan
->dmac_chan
= idx
;
346 cdmac_intr(void *arg
)
351 isr
= bus_space_read_4(&cdmac_bst
, 0, CDMAC_INTR
);
353 if (ISSET(isr
, CDMAC_INTR_TX0
) && cdmacintr
[0].cih_func
) {
354 (cdmacintr
[0].cih_func
)(cdmacintr
[0].cih_arg
);
357 if (ISSET(isr
, CDMAC_INTR_RX0
) && cdmacintr
[1].cih_func
) {
358 (cdmacintr
[1].cih_func
)(cdmacintr
[1].cih_arg
);
362 bus_space_write_4(&cdmac_bst
, 0, CDMAC_INTR
, isr
); /* ack */
364 /* XXX This still happens all the time under load. */
367 aprint_normal("WARNING: stray cdmac isr 0x%x\n", isr
);
377 virtex_autoconf(device_t self
, struct plb_attach_args
*paa
)
380 struct xcvbus_attach_args vaa
;
381 struct ll_dmac rx
, tx
;
384 /* Reset DMA channels. */
385 bus_space_write_4(&cdmac_bst
, 0, CDMAC_STAT_BASE(0), CDMAC_STAT_RESET
);
386 bus_space_write_4(&cdmac_bst
, 0, CDMAC_STAT_BASE(1), CDMAC_STAT_RESET
);
387 bus_space_write_4(&cdmac_bst
, 0, CDMAC_INTR
, 0);
389 vaa
.vaa_dmat
= paa
->plb_dmat
;
391 for (i
= 0; i
< __arraycount(gsrd_devices
); i
++) {
392 const struct gsrddev
*g
= &gsrd_devices
[i
];
394 vaa
._vaa_is_dcr
= g
->gdv_dcr
; /* XXX bst flag */
395 vaa
.vaa_name
= g
->gdv_name
;
396 vaa
.vaa_addr
= g
->gdv_addr
;
397 vaa
.vaa_intr
= g
->gdv_intr
;
398 vaa
.vaa_iot
= g
->gdv_bst
;
400 vaa
.vaa_rx_dmac
= virtex_mpmc_mapdma(g
->gdv_rx_dma
, &rx
);
401 vaa
.vaa_tx_dmac
= virtex_mpmc_mapdma(g
->gdv_tx_dma
, &tx
);
403 config_found_ia(self
, g
->gdv_attr
, &vaa
, xcvbus_print
);
406 /* Setup the dispatch handler. */
407 cdmac_ih
= intr_establish(CDMAC_INTR_LINE
, IST_LEVEL
, IPL_NET
,
409 if (cdmac_ih
== NULL
)
410 panic("virtex_mpmc_done: could not establish cdmac intr");
412 /* Clear (XXX?) and enable interrupts. */
413 bus_space_write_4(&cdmac_bst
, 0, CDMAC_INTR
, ~CDMAC_INTR_MIE
);
414 bus_space_write_4(&cdmac_bst
, 0, CDMAC_INTR
, CDMAC_INTR_MIE
);
418 ll_dmac_intr_establish(int chan
, void (*handler
)(void *), void *arg
)
420 KASSERT(chan
>= 0 && chan
< CDMAC_NCHAN
);
421 KASSERT(cdmacintr
[chan
].cih_func
== NULL
);
422 KASSERT(cdmacintr
[chan
].cih_arg
== NULL
);
424 cdmacintr
[chan
].cih_func
= handler
;
425 cdmacintr
[chan
].cih_arg
= arg
;
427 return (&cdmacintr
[chan
]);
431 ll_dmac_intr_disestablish(int chan
, void *handle
)
435 KASSERT(chan
>= 0 && chan
< CDMAC_NCHAN
);
436 KASSERT(&cdmacintr
[chan
] == handle
);
439 cdmacintr
[chan
].cih_func
= NULL
;
440 cdmacintr
[chan
].cih_arg
= NULL
;
445 virtex_bus_space_tag(const char *xname
, bus_space_tag_t
*bst
)
447 if (strncmp(xname
, "xlcom", 5) == 0) {
456 virtex_machdep_init(vaddr_t endva
, vsize_t maxsz
, struct mem_region
*phys
,
457 struct mem_region
*avail
)
459 ppc4xx_tlb_reserve(OPB_BASE
, endva
, maxsz
, TLB_I
| TLB_G
);
462 opb_bst
.pbs_limit
= maxsz
;
464 if (bus_space_init(&opb_bst
, "opbtag", opb_extent_storage
,
465 sizeof(opb_extent_storage
)))
466 panic("virtex_machdep_init: failed to initialize opb_bst");
469 * The TFT controller is broken, we can't change FB address.
470 * Hardwire it at predefined base address, create uncached
474 avail
[0].size
= TFT_FB_BASE
- avail
[0].start
;
475 ppc4xx_tlb_reserve(TFT_FB_BASE
, endva
, TFT_FB_SIZE
, TLB_I
| TLB_G
);
479 device_register(struct device
*dev
, void *aux
)
484 if (strncmp(device_xname(dev
), "tft0", 4) == 0) {
485 fb
= ppc4xx_tlb_mapiodev(TFT_FB_BASE
, TFT_FB_SIZE
);
487 panic("device_register: framebuffer mapping gone!\n");
489 pn
= prop_number_create_unsigned_integer(TFT_FB_BASE
);
491 printf("WARNING: could not allocate virtex-tft-pa\n");
494 if (prop_dictionary_set(device_properties(dev
),
495 "virtex-tft-pa", pn
) != true)
496 printf("WARNING: could not set virtex-tft-pa\n");
497 prop_object_release(pn
);
499 pn
= prop_number_create_unsigned_integer((uintptr_t)fb
);
501 printf("WARNING: could not allocate virtex-tft-va\n");
504 if (prop_dictionary_set(device_properties(dev
),
505 "virtex-tft-va", pn
) != true)
506 printf("WARNING: could not set virtex-tft-va\n");
507 prop_object_release(pn
);