xref: /netbsd-src/sys/arch/emips/ebus/stub_ebus.c (revision f9228f42259a421502f04b1ddb2df91c2ecbc519)
1 /*	$NetBSD: stub_ebus.c,v 1.4 2014/07/25 08:10:32 dholland 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 STUBSTRUCT *sc_dp;
57 };
58 
59 static int	stub_ebus_match (device_t, cfdata_t, void *);
60 static void	stub_ebus_attach (device_t, device_t, void *);
61 
62 CFATTACH_DECL_NEW(stub_ebus, sizeof (struct stub_softc),
63     stub_ebus_match, stub_ebus_attach, NULL, NULL);
64 
65 static int
stub_ebus_match(device_t parent,cfdata_t match,void * aux)66 stub_ebus_match(device_t parent, cfdata_t match, void *aux)
67 {
68 	struct ebus_attach_args *ia = aux;
69 	struct STUBSTRUCT *f = (struct STUBSTRUCT *)ia->ia_vaddr;
70 
71 	if (strcmp(STUBSTRING, ia->ia_name) != 0)
72 		return (0);
73 	if ((f == NULL) || (! STUBMATCH(f)))
74 		return (0);
75 
76 	return (1);
77 }
78 
79 static void
stub_ebus_attach(device_t parent,device_t self,void * aux)80 stub_ebus_attach(device_t parent, device_t self, void *aux)
81 {
82 	struct ebus_attach_args *ia =aux;
83 	struct stub_softc *sc = device_private(self);
84 
85 	sc->sc_dp = (struct STUBSTRUCT*)ia->ia_vaddr;
86 
87 #if DEBUG
88 	printf(" virt=%p", (void*)sc->sc_dp);
89 #endif
90 	printf(": %s\n", STUBBANNER);
91 
92 }
93 
94 /* Required funcs
95  */
96 static int     stubopen(dev_t device, int flags, int fmt, struct lwp *process);
97 static int     stubclose(dev_t device, int flags, int fmt, struct lwp *process);
98 
99 /* just define the character device handlers because that is all we need */
100 const struct cdevsw stub_cdevsw = {
101 	.d_open = stubopen,
102 	.d_close = stubclose,
103 	.d_read = noread,
104 	.d_write = nowrite,
105 	.d_ioctl = noioctl,
106 	.d_stop = nostop,
107 	.d_tty = notty,
108 	.d_poll = nopoll,
109 	.d_mmap = nommap,
110 	.d_kqfilter = nokqfilter,
111 	.d_discard = nodiscard,
112 	.d_flag = 0
113 };
114 
115 /*
116  * Handle an open request on the device.
117  */
118 static int
stubopen(dev_t device,int flags,int fmt,struct lwp * process)119 stubopen(dev_t device, int flags, int fmt, struct lwp *process)
120 {
121 	return 0; /* this always succeeds */
122 }
123 
124 /*
125  * Handle the close request for the device.
126  */
127 static int
stubclose(dev_t device,int flags,int fmt,struct lwp * process)128 stubclose(dev_t device, int flags, int fmt, struct lwp *process)
129 {
130 	return 0; /* again this always succeeds */
131 }
132