summaryrefslogtreecommitdiff
path: root/sys/dev/marvell/obio.c
blob: 3ec81181d55898e3c2610b5e7d8ced0d1a7ca937 (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
/*	$NetBSD: obio.c,v 1.3 2003/07/14 15:47:18 lukem Exp $	*/

/*
 * Copyright (c) 2002 Allegro Networks, Inc., Wasabi Systems, Inc.
 * All rights reserved.
 *
 * 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.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed for the NetBSD Project by
 *      Allegro Networks, Inc., and Wasabi Systems, Inc.
 * 4. The name of Allegro Networks, Inc. may not be used to endorse
 *    or promote products derived from this software without specific prior
 *    written permission.
 * 5. The name of Wasabi Systems, Inc. may not be used to endorse
 *    or promote products derived from this software without specific prior
 *    written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY ALLEGRO NETWORKS, INC. AND
 * WASABI SYSTEMS, INC. ``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 EITHER ALLEGRO NETWORKS, INC. OR WASABI SYSTEMS, INC.
 * 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.
 */

/*
 * gt.c -- GT system controller driver
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: obio.c,v 1.3 2003/07/14 15:47:18 lukem Exp $");

#include "opt_marvell.h"

#include <sys/param.h>
#include <sys/types.h>
#include <sys/cdefs.h>
#include <sys/extent.h>
#include <sys/device.h>
#include <sys/kernel.h>
#include <sys/malloc.h>

#define _BUS_SPACE_PRIVATE
#define _BUS_DMA_PRIVATE
#include <machine/bus.h>

#include <powerpc/spr.h>
#include <powerpc/oea/hid.h>

#include <dev/pci/pcivar.h>
#include <dev/marvell/gtreg.h>
#include <dev/marvell/gtvar.h>

#ifdef DEBUG
#include <sys/systm.h>	/* for Debugger() */
#endif

static int obio_cfprint(void *, const char *);
static int obio_cfmatch(struct device *, struct cfdata *, void *);
static int obio_cfsearch(struct device *, struct cfdata *, void *);
static void obio_cfattach(struct device *, struct device *, void *);

struct obio_softc {
	struct device sc_dev;
	bus_space_tag_t sc_memt;
	bus_space_tag_t sc_gt_memt;
	bus_space_tag_t sc_gt_memh;
};

CFATTACH_DECL(obio, sizeof(struct obio_softc),
    obio_cfmatch, obio_cfattach, NULL, NULL);

extern struct cfdriver obio_cd;

static const struct {
    bus_addr_t low_decode;
    bus_addr_t high_decode;
} obio_info[5] = {
    { GT_CS0_Low_Decode, GT_CS0_High_Decode, },
    { GT_CS1_Low_Decode, GT_CS1_High_Decode, },
    { GT_CS2_Low_Decode, GT_CS2_High_Decode, },
    { GT_CS3_Low_Decode, GT_CS3_High_Decode, },
    { GT_BootCS_Low_Decode, GT_BootCS_High_Decode, },
};

extern bus_space_tag_t obio_bs_tags[5];

int
obio_cfprint(void *aux, const char *pnp)
{
	struct obio_attach_args *oa = aux;

	if (pnp) {
		aprint_normal("%s at %s", oa->oa_name, pnp);
	}
	aprint_normal(" offset %#x size %#x", oa->oa_offset, oa->oa_size);
	if (oa->oa_irq != OBIO_UNK_IRQ)
		aprint_normal(" irq %d", oa->oa_irq);

	return (UNCONF);
}


int
obio_cfsearch(struct device *parent, struct cfdata *cf, void *aux)
{
	struct obio_softc *sc = (struct obio_softc *) parent;
	struct obio_attach_args oa;

	oa.oa_name = cf->cf_name;
	oa.oa_memt = sc->sc_memt;
	oa.oa_offset = cf->obiocf_offset;
	oa.oa_size = cf->obiocf_size;
	oa.oa_irq = cf->obiocf_irq;

	if (config_match(parent, cf, &oa) > 0)
		config_attach(parent, cf, &oa, obio_cfprint);

	return (0);
}

int
obio_cfmatch(struct device *parent, struct cfdata *cf, void *aux)
{
	struct gt_softc * const gt = (struct gt_softc *)parent;
	struct gt_attach_args * const ga = aux;

	return GT_OBIOOK(gt, ga, &obio_cd);
}

void
obio_cfattach(struct device *parent, struct device *self, void *aux)
{
	struct gt_softc * const gt = (struct gt_softc *)parent;
	struct obio_softc *sc = (struct obio_softc *)self;
	struct gt_attach_args *ga = aux;
	uint32_t datal, datah;

	GT_OBIOFOUND(gt, ga);

	datal = bus_space_read_4(ga->ga_memt, ga->ga_memh,
	    obio_info[ga->ga_unit].low_decode);
	datah = bus_space_read_4(ga->ga_memt, ga->ga_memh,
	    obio_info[ga->ga_unit].high_decode);

	if (GT_LowAddr_GET(datal) > GT_HighAddr_GET(datah)) {
		aprint_normal(": disabled\n");
		return;
	}

	sc->sc_memt = obio_bs_tags[ga->ga_unit];
	if (sc->sc_memt == NULL) {
		aprint_normal(": unused\n");
		return;
	}

	aprint_normal(": addr %#x-%#x, %s-endian\n",
	    GT_LowAddr_GET(datal), GT_HighAddr_GET(datah),
	    GT_PCISwap_GET(datal) == 1 ? "little" : "big");

        config_search(obio_cfsearch, &sc->sc_dev, NULL);
}