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