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