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