summaryrefslogtreecommitdiff
path: root/sys/arch/powerpc/ibm4xx/dev/exb.c
blob: 3f510cc4444027ad436abb8990875e237f2b0c9c (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
/*	$Id: exb.c,v 1.5 2021/08/07 16:19:03 thorpej Exp $	*/

/*-
 * Copyright (c) 2010 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software developed for The NetBSD Foundation
 * by Masao Uebayashi.
 *
 * 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: exb.c,v 1.5 2021/08/07 16:19:03 thorpej Exp $");

#include "locators.h"

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

#include <powerpc/ibm4xx/dcr4xx.h>
#include <powerpc/ibm4xx/dev/exbvar.h>

struct exb_softc {
};

extern const struct exb_conf exb_confs[];

static int exb_match(device_t, cfdata_t, void *);
static void exb_attach(device_t, device_t, void *);
static int exb_print(void *, const char *);

CFATTACH_DECL_NEW(exb, sizeof(struct exb_softc), exb_match, exb_attach,
    NULL, NULL);

static struct powerpc_bus_space exb_bus_space_tag =
    { _BUS_SPACE_BIG_ENDIAN | _BUS_SPACE_MEM_TYPE, 0 };

static int
exb_match(device_t parent, cfdata_t cf, void *aux)
{

	return 1;
}

static void
exb_attach(device_t parent, device_t self, void *aux)
{
	const struct exb_conf *ec = exb_confs;
	uint32_t ebc0_bNcr;
	bus_addr_t base, size;
	int locs[EXBCF_NLOCS];

	printf("\n");

	/* mtdcr needs a constant */
	switch (device_unit(self)) {
	case 0: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B0CR);	break;
	case 1: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B1CR);	break;
	case 2: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B2CR);	break;
	case 3: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B3CR);	break;
	case 4: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B4CR);	break;
	case 5: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B5CR);	break;
	case 6: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B6CR);	break;
	case 7: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B7CR);	break;
	}
	ebc0_bNcr = mfdcr(DCR_EBC0_CFGDATA);
	base = ebc0_bNcr & 0xfff00000;
	size = 0x00100000 << ((ebc0_bNcr & 0x000e0000) >> 17);

	exb_bus_space_tag.pbs_base = base;
	exb_bus_space_tag.pbs_limit = base + size - 1;

	while (ec->ec_name) {
		struct exb_conf ec1;

		locs[EXBCF_ADDR] = ec->ec_addr;

		ec1 = *ec;
		ec1.ec_bust = exb_get_bus_space_tag();

		config_found(self, &ec1, exb_print,
		    CFARGS(.submatch = config_stdsubmatch,
			   .locators = locs));
		ec++;
	}
}

static int
exb_print(void *aux, const char *bus)
{
	struct exb_conf *ec = aux;

	if (bus)
		return QUIET;

	if (ec->ec_addr)
		printf(" addr %"PRIxBUSADDR, ec->ec_addr);

	return UNCONF;
}

bus_space_tag_t
exb_get_bus_space_tag(void)
{
	static char ex_storage[EXTENT_FIXED_STORAGE_SIZE(8)]
	    __attribute__((aligned(8)));
	static int exb_bus_space_tag_inited;

	if (exb_bus_space_tag_inited == 0) {
		if (bus_space_init(&exb_bus_space_tag, "exbtag",
		    ex_storage, sizeof(ex_storage)))
			panic("exb_attach: Failed to initialise exb_bus_space_tag");
		exb_bus_space_tag_inited = 1;
	}
	return &exb_bus_space_tag;
}