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