Home | History | Annotate | Line # | Download | only in apbus
      1 /*	$NetBSD: apbus_subr.c,v 1.10 2018/09/30 06:14:23 tsutsui Exp $	*/
      2 
      3 /*-
      4  * Copyright (C) 1999 SHIMIZU Ryo.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. The name of the author may not be used to endorse or promote products
     15  *    derived from this software without specific prior written permission.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 __KERNEL_RCSID(0, "$NetBSD: apbus_subr.c,v 1.10 2018/09/30 06:14:23 tsutsui Exp $");
     31 
     32 #include <sys/param.h>
     33 #include <sys/systm.h>
     34 
     35 #include <uvm/uvm_extern.h>
     36 
     37 #include <mips/locore.h>
     38 #include <mips/pte.h>
     39 
     40 #include <machine/wired_map.h>
     41 
     42 #include <newsmips/apbus/apbusvar.h>
     43 
     44 static void apctl_dump(struct apbus_ctl *);
     45 
     46 #define	APBUS_ROMWORK_VA	0xfff00000
     47 
     48 void
     49 apbus_map_romwork(void)
     50 {
     51 	static bool mapped = false;
     52 	vaddr_t apbd_work_va;
     53 	vsize_t apbd_work_sz;
     54 	paddr_t apbd_work_pa;
     55 
     56 	if (!mapped) {
     57 		/* map PROM work RAM into VA 0xFFF00000 - 0xFFFFFFFF */
     58 		apbd_work_va = APBUS_ROMWORK_VA;
     59 		apbd_work_sz = MIPS3_PG_SIZE_MASK_TO_SIZE(MIPS3_PG_SIZE_1M);
     60 		apbd_work_pa = ctob(physmem);
     61 
     62 		mapped = mips3_wired_enter_page(apbd_work_va, apbd_work_pa,
     63 		    apbd_work_sz);
     64 		if (!mapped) {
     65 			printf("%s: cannot allocate APbus PROM work\n",
     66 			    __func__);
     67 		}
     68 	}
     69 }
     70 
     71 void *
     72 apbus_device_to_hwaddr(struct apbus_dev *apbus_dev)
     73 {
     74 	struct apbus_ctl *ctl;
     75 
     76 	if (apbus_dev == NULL)
     77 		return NULL;
     78 
     79 	ctl = apbus_dev->apbd_ctl;
     80 	if (ctl == NULL)
     81 		return NULL;
     82 
     83 	return (void *)ctl->apbc_hwbase;
     84 }
     85 
     86 struct apbus_dev *
     87 apbus_lookupdev(char *devname)
     88 {
     89 	struct apbus_dev *dp;
     90 
     91 	dp = _sip->apbsi_dev;
     92 	if (devname == NULL || *devname == '\0')
     93 		return dp;
     94 
     95 	/* search apbus_dev named 'devname' */
     96 	while (dp) {
     97 		if (strcmp(devname, dp->apbd_name) == 0)
     98 			return dp;
     99 
    100 		dp = dp->apbd_link;
    101 	}
    102 
    103 	return NULL;
    104 }
    105 
    106 static void
    107 apctl_dump(struct apbus_ctl *apctl)
    108 {
    109 	if (!apctl)
    110 		return;
    111 
    112 	printf("	apbus_ctl dump (%p)\n", apctl);
    113 
    114 	printf("	Num:		%d\n", apctl->apbc_ctlno);
    115 	printf("	HWaddr:		0x%08x\n", apctl->apbc_hwbase);
    116 	printf("	softc:		%p\n", apctl->apbc_softc);
    117 	printf("	Slot:		%d\n", apctl->apbc_sl);
    118 	printf("\n");
    119 
    120 	if (apctl->apbc_link)
    121 		apctl_dump(apctl->apbc_link);
    122 }
    123 
    124 void
    125 apdevice_dump(struct apbus_dev *apdev)
    126 {
    127 	struct apbus_ctl *apctl;
    128 
    129 	if (apdev == NULL)
    130 		return;
    131 
    132 	/* only no pseudo device */
    133 	apctl = apdev->apbd_ctl;
    134 	if (apctl == NULL || apctl->apbc_hwbase == 0)
    135 		return;
    136 
    137 	printf("apbus_dev dump (%p)\n", apdev);
    138 	printf("name:		%s\n", apdev->apbd_name);
    139 	printf("vendor:		%s\n", apdev->apbd_vendor);
    140 	printf("atr:		%08x\n", apdev->apbd_atr);
    141 	printf("rev:		%d\n", apdev->apbd_rev);
    142 	printf("driver:		0x%08x\n", (unsigned int)apdev->apbd_driver);
    143 	printf("ctl:		0x%08x\n", (unsigned int)apdev->apbd_ctl);
    144 	printf("link:		0x%08x\n", (unsigned int)apdev->apbd_link);
    145 	printf("\n");
    146 
    147 	apctl_dump(apctl);
    148 }
    149