xref: /netbsd/sys/arch/next68k/next68k/mainbus.c (revision c4a72b64)
1 /*	$NetBSD: mainbus.c,v 1.4 2002/10/02 04:22:54 thorpej 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 Jason R. Thorpe.
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  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *        This product includes software developed by the NetBSD
21  *        Foundation, Inc. and its contributors.
22  * 4. Neither the name of The NetBSD Foundation nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36  * POSSIBILITY OF SUCH DAMAGE.
37  */
38 
39 #include <sys/param.h>
40 #include <sys/device.h>
41 #include <sys/systm.h>
42 
43 #define _M68K_BUS_DMA_PRIVATE
44 #include <machine/autoconf.h>
45 
46 static int	mainbus_match __P((struct device *, struct cfdata *, void *));
47 static void	mainbus_attach __P((struct device *, struct device *, void *));
48 static int	mainbus_search __P((struct device *, struct cfdata *, void *));
49 
50 CFATTACH_DECL(mainbus, sizeof(struct device),
51     mainbus_match, mainbus_attach, NULL, NULL);
52 
53 struct m68k_bus_dma_tag next68k_bus_dma_tag = {
54 	NULL,					/* _cookie */
55 
56 	0,					/* _boundary */
57 
58 	_bus_dmamap_create,			/* _dmamap_create */
59 	_bus_dmamap_destroy,			/* _dmamap_destroy */
60 	_bus_dmamap_load_direct,		/* _dmamap_load */
61 	_bus_dmamap_load_mbuf_direct,		/* _dmamap_load_mbuf */
62 	_bus_dmamap_load_uio_direct,		/* _dmamap_load_uio */
63 	_bus_dmamap_load_raw_direct,		/* _dmamap_load_raw */
64 	_bus_dmamap_unload,			/* _dmamap_unload */
65 	_bus_dmamap_sync,			/* _dmamap_sync */
66 
67 	_bus_dmamem_alloc,			/* _dmamem_alloc */
68 	_bus_dmamem_free,			/* _dmamem_free */
69 	_bus_dmamem_map,			/* _dmamem_map */
70 	_bus_dmamem_unmap,			/* _dmamem_unmap */
71 	_bus_dmamem_mmap			/* _dmamem_mmap */
72 };
73 
74 static int mainbus_attached = 0;
75 
76 static int
77 mainbus_match(parent, cf, aux)
78 	struct device *parent;
79 	struct cfdata *cf;
80 	void *aux;
81 {
82 	/* Allow only one instance. */
83 	if (mainbus_attached)
84 		return (0);
85 
86 	return 1;
87 }
88 
89 static void
90 mainbus_attach(parent, self, aux)
91 	struct device	*parent, *self;
92 	void		*aux;
93 {
94 	struct mainbus_attach_args	mba;
95 
96 	printf("\n");
97 
98 	mba.mba_dmat = &next68k_bus_dma_tag;
99 
100 	/* Search for and attach children. */
101 	config_search(mainbus_search, self, &mba);
102 
103 	mainbus_attached = 1;
104 }
105 
106 static int
107 mainbus_search(parent, cf, aux)
108 	struct device *parent;
109 	struct cfdata *cf;
110 	void *aux;
111 {
112 	if (config_match(parent, cf, aux) > 0)
113 		config_attach(parent, cf, aux, NULL);
114 	return 0;
115 }
116