xref: /netbsd/sys/arch/mac68k/mac68k/mainbus.c (revision bf9ec67e)
1 /*	$NetBSD: mainbus.c,v 1.11 2002/04/13 17:49:41 briggs 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 struct cfattach mainbus_ca = {
51 	sizeof(struct device), mainbus_match, mainbus_attach
52 };
53 
54 struct m68k_bus_dma_tag mac68k_bus_dma_tag = {
55 	NULL,					/* _cookie */
56 
57 	0,					/* _boundary */
58 
59 	_bus_dmamap_create,			/* _dmamap_create */
60 	_bus_dmamap_destroy,			/* _dmamap_destroy */
61 	_bus_dmamap_load_direct,		/* _dmamap_load */
62 	_bus_dmamap_load_mbuf_direct,		/* _dmamap_load_mbuf */
63 	_bus_dmamap_load_uio_direct,		/* _dmamap_load_uio */
64 	_bus_dmamap_load_raw_direct,		/* _dmamap_load_raw */
65 	_bus_dmamap_unload,			/* _dmamap_unload */
66 	_bus_dmamap_sync,			/* _dmamap_sync */
67 
68 	_bus_dmamem_alloc,			/* _dmamem_alloc */
69 	_bus_dmamem_free,			/* _dmamem_free */
70 	_bus_dmamem_map,			/* _dmamem_map */
71 	_bus_dmamem_unmap,			/* _dmamem_unmap */
72 	_bus_dmamem_mmap			/* _dmamem_mmap */
73 };
74 
75 static int
76 mainbus_match(parent, cf, aux)
77 	struct device *parent;
78 	struct cfdata *cf;
79 	void *aux;
80 {
81 	static int mainbus_matched = 0;
82 
83 	/* Allow only one instance. */
84 	if (mainbus_matched)
85 		return (0);
86 
87 	mainbus_matched = 1;
88 	return 1;
89 }
90 
91 static void
92 mainbus_attach(parent, self, aux)
93 	struct device	*parent, *self;
94 	void		*aux;
95 {
96 	struct mainbus_attach_args	mba;
97 
98 	printf("\n");
99 
100 	mba.mba_bst = MAC68K_BUS_SPACE_MEM;
101 	mba.mba_dmat = &mac68k_bus_dma_tag;
102 
103 	/* Search for and attach children. */
104 	config_search(mainbus_search, self, &mba);
105 }
106 
107 static int
108 mainbus_search(parent, cf, aux)
109 	struct device *parent;
110 	struct cfdata *cf;
111 	void *aux;
112 {
113 	if ((*cf->cf_attach->ca_match)(parent, cf, aux) > 0)
114 		config_attach(parent, cf, aux, NULL);
115 	return 0;
116 }
117