1/*	$NetBSD: obmem.c,v 1.25 2008/04/28 20:23:38 martin Exp $	*/
2
3/*-
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Adam Glass and Gordon W. Ross.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32/*
33 * On-board MEMory (OBMEM)
34 * Used by frame buffers...
35 */
36
37#include <sys/cdefs.h>
38__KERNEL_RCSID(0, "$NetBSD: obmem.c,v 1.25 2008/04/28 20:23:38 martin Exp $");
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/device.h>
43
44#include <uvm/uvm_extern.h>
45
46#include <machine/autoconf.h>
47#include <machine/bus.h>
48#include <sun3/sun3/obmem.h>
49
50static int  obmem_match(device_t, cfdata_t, void *);
51static void obmem_attach(device_t, device_t, void *);
52
53struct obmem_softc {
54	device_t	sc_dev;
55	bus_space_tag_t	sc_bustag;
56	bus_dma_tag_t	sc_dmatag;
57};
58
59CFATTACH_DECL_NEW(obmem, sizeof(struct obmem_softc),
60    obmem_match, obmem_attach, NULL, NULL);
61
62static int obmem_attached;
63
64static int obmem_bus_map(bus_space_tag_t, bus_type_t, bus_addr_t, bus_size_t,
65    int, vaddr_t, bus_space_handle_t *);
66static paddr_t obmem_bus_mmap(bus_space_tag_t, bus_type_t, bus_addr_t, off_t,
67    int, int);
68
69static struct sun68k_bus_space_tag obmem_space_tag = {
70	NULL,				/* cookie */
71	NULL,				/* parent bus space tag */
72	obmem_bus_map,			/* bus_space_map */
73	NULL,				/* bus_space_unmap */
74	NULL,				/* bus_space_subregion */
75	NULL,				/* bus_space_barrier */
76	obmem_bus_mmap,			/* bus_space_mmap */
77	NULL,				/* bus_intr_establish */
78	NULL,				/* bus_space_peek_N */
79	NULL				/* bus_space_poke_N */
80};
81
82static int
83obmem_match(device_t parent, cfdata_t cf, void *aux)
84{
85	struct confargs *ca = aux;
86
87	if (obmem_attached)
88		return 0;
89
90	if (ca->ca_bustype != BUS_OBMEM)
91		return 0;
92
93	if (ca->ca_name != NULL && strcmp(cf->cf_name, ca->ca_name) != 0)
94		return 0;
95
96	return 1;
97}
98
99static void
100obmem_attach(device_t parent, device_t self, void *aux)
101{
102	struct confargs *ca = aux;
103	struct obmem_softc *sc = device_private(self);
104	struct confargs obma;
105
106	obmem_attached = 1;
107	sc->sc_dev = self;
108
109	aprint_normal("\n");
110
111	sc->sc_bustag = ca->ca_bustag;
112	sc->sc_dmatag = ca->ca_dmatag;
113
114	obmem_space_tag.cookie = sc;
115	obmem_space_tag.parent = sc->sc_bustag;
116
117	obma = *ca;
118	obma.ca_bustag = &obmem_space_tag;
119
120	/* We know ca_bustype == BUS_OBMEM */
121	config_search_ia(bus_scan, self, "obmem", &obma);
122}
123
124int
125obmem_bus_map(bus_space_tag_t t, bus_type_t btype, bus_addr_t paddr,
126    bus_size_t size, int flags, vaddr_t vaddr, bus_space_handle_t *hp)
127{
128	struct obmem_softc *sc = t->cookie;
129
130	return bus_space_map2(sc->sc_bustag, PMAP_OBMEM, paddr, size, flags,
131	    vaddr, hp);
132}
133
134paddr_t
135obmem_bus_mmap(bus_space_tag_t t, bus_type_t btype, bus_addr_t paddr, off_t off,
136    int prot, int flags)
137{
138	struct obmem_softc *sc = t->cookie;
139
140	return bus_space_mmap2(sc->sc_bustag, PMAP_OBMEM, paddr, off, prot,
141	    flags);
142}
143