xref: /netbsd/sys/arch/emips/ebus/stub_ebus.c (revision 6550d01e)
1 /*	$NetBSD: stub_ebus.c,v 1.1 2011/01/26 01:18:50 pooka Exp $	*/
2 
3 /*-
4  * Copyright (c) 2010 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code was written by Alessandro Forin and Neil Pittman
8  * at Microsoft Research and contributed to The NetBSD Foundation
9  * by Microsoft Corporation.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 /* Before including this file for "foo" you need to define
34 #define STUBSTRING       "foo"
35 #define STUBBANNER       "8MB flash memory"  -- tell the user what it is
36 #define STUBSTRUCT       _Flash   -- whatever that struct is defined in emipsreg.h
37 #define STUBMATCH(_f_)   (((_f_)->BaseAddressAndTag & FLASHBT_TAG) == PMTTAG_FLASH)
38  */
39 
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/proc.h>
43 #include <sys/errno.h>
44 #include <sys/ioctl.h>
45 #include <sys/device.h>
46 #include <sys/conf.h>
47 
48 #include <emips/ebus/ebusvar.h>
49 #include <emips/emips/machdep.h>
50 #include <machine/emipsreg.h>
51 
52 /*
53  * Device softc
54  */
55 struct stub_softc {
56 	struct device sc_dev;
57 	struct STUBSTRUCT *sc_dp;
58 };
59 
60 static int	stub_ebus_match (struct device *, struct cfdata *, void *);
61 static void	stub_ebus_attach (struct device *, struct device *, void *);
62 
63 CFATTACH_DECL(stub_ebus, sizeof (struct stub_softc),
64     stub_ebus_match, stub_ebus_attach, NULL, NULL);
65 
66 static int
67 stub_ebus_match(struct device *parent, struct cfdata *match, void *aux)
68 {
69 	struct ebus_attach_args *ia = aux;
70 	struct STUBSTRUCT *f = (struct STUBSTRUCT *)ia->ia_vaddr;
71 
72 	if (strcmp(STUBSTRING, ia->ia_name) != 0)
73 		return (0);
74 	if ((f == NULL) || (! STUBMATCH(f)))
75 		return (0);
76 
77 	return (1);
78 }
79 
80 static void
81 stub_ebus_attach(struct device *parent, struct device *self, void *aux)
82 {
83 	struct ebus_attach_args *ia =aux;
84 	struct stub_softc *sc = (struct stub_softc *)self;
85 
86 	sc->sc_dp = (struct STUBSTRUCT*)ia->ia_vaddr;
87 
88 #if DEBUG
89 	printf(" virt=%p", (void*)sc->sc_dp);
90 #endif
91 	printf(": %s\n", STUBBANNER);
92 
93 }
94 
95 /* Required funcs
96  */
97 static int     stubopen(dev_t device, int flags, int fmt, struct lwp *process);
98 static int     stubclose(dev_t device, int flags, int fmt, struct lwp *process);
99 
100 /* just define the character device handlers because that is all we need */
101 const struct cdevsw stub_cdevsw = {
102 	stubopen,
103 	stubclose,
104 	noread,
105 	nowrite,
106 	noioctl,
107 	nostop,
108 	notty,
109 	nopoll,
110 	nommap,
111 	nokqfilter,
112 };
113 
114 /*
115  * Handle an open request on the device.
116  */
117 static int
118 stubopen(dev_t device, int flags, int fmt, struct lwp *process)
119 {
120 	return 0; /* this always succeeds */
121 }
122 
123 /*
124  * Handle the close request for the device.
125  */
126 static int
127 stubclose(dev_t device, int flags, int fmt, struct lwp *process)
128 {
129 	return 0; /* again this always succeeds */
130 }
131