summaryrefslogtreecommitdiff
path: root/sys/arch/evbppc/explora/dev/elb.c
blob: e214538d8d365655c2d0987fb376f37c5a821e17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*	$NetBSD: elb.c,v 1.11 2021/08/07 16:18:52 thorpej Exp $	*/

/*-
 * Copyright (c) 2003 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Juergen Hannken-Illjes.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: elb.c,v 1.11 2021/08/07 16:18:52 thorpej Exp $");

#include <sys/param.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <sys/systm.h>
#include <sys/extent.h>

#include <machine/explora.h>
#define _POWERPC_BUS_DMA_PRIVATE
#include <sys/bus.h>

#include <powerpc/ibm4xx/dcr403cgx.h>

#include <evbppc/explora/dev/elbvar.h>

struct elb_dev {
	const char *elb_name;
	int elb_addr;
	int elb_addr2;
	int elb_irq;
	bus_space_tag_t elb_bt;
};

static int	elb_match(device_t, cfdata_t, void *);
static void	elb_attach(device_t, device_t, void *);
static int	elb_print(void *, const char *);

static struct powerpc_bus_space elb_tag = {
	_BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_MEM_TYPE | 1,	/* stride 1 */
	0x00000000,
	BASE_PCKBC,
	BASE_PCKBC + 0x6ff
};
static struct powerpc_bus_space elb_fb_tag = {
	_BUS_SPACE_LITTLE_ENDIAN | _BUS_SPACE_MEM_TYPE,
	0x00000000,
	BASE_FB,
	BASE_FB2 + SIZE_FB - 1
};

static char elb_ex_storage[EXTENT_FIXED_STORAGE_SIZE(8)]
    __attribute__((aligned(8)));
static char elbfb_ex_storage[EXTENT_FIXED_STORAGE_SIZE(8)]
    __attribute__((aligned(8)));

static bool elb_tag_init_done;
static bool elbfb_tag_init_done;

/*
 * DMA struct, nothing special.
 */
static struct powerpc_bus_dma_tag elb_bus_dma_tag = {
	0,			/* _bounce_thresh */
	_bus_dmamap_create, 
	_bus_dmamap_destroy,
	_bus_dmamap_load,
	_bus_dmamap_load_mbuf,
	_bus_dmamap_load_uio,
	_bus_dmamap_load_raw,
	_bus_dmamap_unload,
	_bus_dmamap_sync,
	_bus_dmamem_alloc,
	_bus_dmamem_free,
	_bus_dmamem_map,
	_bus_dmamem_unmap,
	_bus_dmamem_mmap,
	_bus_dma_phys_to_bus_mem_generic,
	_bus_dma_bus_mem_to_phys_generic,
};

static const struct elb_dev elb_devs[] = {
	{ "cpu",	0,		0,		-1, NULL },
	{ "pckbc",	BASE_PCKBC,	BASE_PCKBC2,	31, &elb_tag },
	{ "com",	BASE_COM,	0,		30, &elb_tag },
	{ "lpt",	BASE_LPT,	0,		-1, &elb_tag },
	{ "fb",		BASE_FB,	BASE_FB2,	-1, &elb_fb_tag },
	{ "le",		BASE_LE,	0,		28, &elb_fb_tag },
};

CFATTACH_DECL_NEW(elb, 0,
    elb_match, elb_attach, NULL, NULL);

/*
 * Probe for the elb; always succeeds.
 */
static int
elb_match(device_t parent, cfdata_t cf, void *aux)
{
	return (1);
}

/*
 * Attach the Explora local bus.
 */
static void
elb_attach(device_t parent, device_t self, void *aux)
{
	struct elb_attach_args eaa;
	const struct elb_dev *elb;
	size_t i;

	printf("\n");
	for (i = 0, elb = elb_devs; i < __arraycount(elb_devs); i++, elb++) {
		eaa.elb_name = elb->elb_name;
		eaa.elb_bt = elb_get_bus_space_tag(elb->elb_addr);
		eaa.elb_dmat = &elb_bus_dma_tag;
		eaa.elb_base = elb->elb_addr;
		eaa.elb_base2 = elb->elb_addr2;
		eaa.elb_irq = elb->elb_irq;

		(void) config_found(self, &eaa, elb_print, CFARGS_NONE);
	}
}

static int
elb_print(void *aux, const char *pnp)
{
	struct elb_attach_args *eaa = aux;

	if (pnp)
		aprint_normal("%s at %s", eaa->elb_name, pnp);
	if (eaa->elb_irq != -1)
		aprint_normal(" irq %d", eaa->elb_irq);

	return (UNCONF);
}

bus_space_tag_t
elb_get_bus_space_tag(bus_addr_t addr)
{

	if ((addr & 0xff000000) == 0x74000000) {
		if (!elb_tag_init_done) {
			if (bus_space_init(&elb_tag, "elbtag",
			    elb_ex_storage, sizeof(elb_ex_storage)))
				panic("elb_get_bus_space_tag: elb_tag");

			elb_tag_init_done = true;
		}
		return (&elb_tag);
	} else {
		if (!elbfb_tag_init_done) {
			if (bus_space_init(&elb_fb_tag, "elbfbtag",
			    elbfb_ex_storage, sizeof(elbfb_ex_storage)))
				panic("elb_get_bus_space_tag: elb_fb_tag");

			elbfb_tag_init_done = true;
		}
		return (&elb_fb_tag);
	}
}