machdep.c revision 1.54.2.1       1  1.54.2.1      yamt /*	$NetBSD: machdep.c,v 1.54.2.1 2012/10/30 17:19:32 yamt Exp $	*/
      2       1.1       scw 
      3       1.1       scw /*
      4       1.1       scw  * Copyright 2001, 2002 Wasabi Systems, Inc.
      5       1.1       scw  * All rights reserved.
      6       1.1       scw  *
      7       1.1       scw  * Written by Eduardo Horvath and Simon Burge for Wasabi Systems, Inc.
      8       1.1       scw  *
      9       1.1       scw  * Redistribution and use in source and binary forms, with or without
     10       1.1       scw  * modification, are permitted provided that the following conditions
     11       1.1       scw  * are met:
     12       1.1       scw  * 1. Redistributions of source code must retain the above copyright
     13       1.1       scw  *    notice, this list of conditions and the following disclaimer.
     14       1.1       scw  * 2. Redistributions in binary form must reproduce the above copyright
     15       1.1       scw  *    notice, this list of conditions and the following disclaimer in the
     16       1.1       scw  *    documentation and/or other materials provided with the distribution.
     17       1.1       scw  * 3. All advertising materials mentioning features or use of this software
     18       1.1       scw  *    must display the following acknowledgement:
     19       1.1       scw  *      This product includes software developed for the NetBSD Project by
     20       1.1       scw  *      Wasabi Systems, Inc.
     21       1.1       scw  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22       1.1       scw  *    or promote products derived from this software without specific prior
     23       1.1       scw  *    written permission.
     24       1.1       scw  *
     25       1.1       scw  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26       1.1       scw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27       1.1       scw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28       1.1       scw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29       1.1       scw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30       1.1       scw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31       1.1       scw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32       1.1       scw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33       1.1       scw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34       1.1       scw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35       1.1       scw  * POSSIBILITY OF SUCH DAMAGE.
     36       1.1       scw  */
     37       1.1       scw 
     38       1.1       scw /*
     39       1.1       scw  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
     40       1.1       scw  * Copyright (C) 1995, 1996 TooLs GmbH.
     41       1.1       scw  * All rights reserved.
     42       1.1       scw  *
     43       1.1       scw  * Redistribution and use in source and binary forms, with or without
     44       1.1       scw  * modification, are permitted provided that the following conditions
     45       1.1       scw  * are met:
     46       1.1       scw  * 1. Redistributions of source code must retain the above copyright
     47       1.1       scw  *    notice, this list of conditions and the following disclaimer.
     48       1.1       scw  * 2. Redistributions in binary form must reproduce the above copyright
     49       1.1       scw  *    notice, this list of conditions and the following disclaimer in the
     50       1.1       scw  *    documentation and/or other materials provided with the distribution.
     51       1.1       scw  * 3. All advertising materials mentioning features or use of this software
     52       1.1       scw  *    must display the following acknowledgement:
     53       1.1       scw  *	This product includes software developed by TooLs GmbH.
     54       1.1       scw  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     55       1.1       scw  *    derived from this software without specific prior written permission.
     56       1.1       scw  *
     57       1.1       scw  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     58       1.1       scw  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     59       1.1       scw  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     60       1.1       scw  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     61       1.1       scw  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     62       1.1       scw  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     63       1.1       scw  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     64       1.1       scw  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     65       1.1       scw  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     66       1.1       scw  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     67       1.1       scw  */
     68      1.14     lukem 
     69      1.14     lukem #include <sys/cdefs.h>
     70  1.54.2.1      yamt __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.54.2.1 2012/10/30 17:19:32 yamt Exp $");
     71       1.1       scw 
     72       1.1       scw #include "opt_compat_netbsd.h"
     73       1.1       scw #include "opt_ddb.h"
     74       1.1       scw #include "opt_ipkdb.h"
     75       1.1       scw 
     76       1.1       scw #include <sys/param.h>
     77      1.52      matt #include <sys/boot_flag.h>
     78       1.1       scw #include <sys/buf.h>
     79      1.52      matt #include <sys/bus.h>
     80      1.52      matt #include <sys/cpu.h>
     81      1.52      matt #include <sys/device.h>
     82       1.1       scw #include <sys/exec.h>
     83      1.52      matt #include <sys/kernel.h>
     84      1.52      matt #include <sys/ksyms.h>
     85       1.1       scw #include <sys/malloc.h>
     86       1.1       scw #include <sys/mbuf.h>
     87      1.52      matt #include <sys/module.h>
     88       1.1       scw #include <sys/mount.h>
     89       1.1       scw #include <sys/msgbuf.h>
     90       1.1       scw #include <sys/proc.h>
     91       1.1       scw #include <sys/reboot.h>
     92       1.1       scw #include <sys/syscallargs.h>
     93       1.1       scw #include <sys/syslog.h>
     94       1.1       scw #include <sys/systm.h>
     95       1.1       scw 
     96       1.1       scw #include <uvm/uvm_extern.h>
     97       1.1       scw 
     98      1.27   thorpej #include <prop/proplib.h>
     99      1.27   thorpej 
    100       1.1       scw #include <machine/powerpc.h>
    101       1.1       scw #include <machine/walnut.h>
    102      1.52      matt 
    103      1.52      matt #include <powerpc/trap.h>
    104      1.52      matt #include <powerpc/pcb.h>
    105       1.1       scw 
    106       1.1       scw #include <powerpc/spr.h>
    107      1.45      matt #include <powerpc/ibm4xx/spr.h>
    108      1.51      matt #include <powerpc/ibm4xx/cpu.h>
    109      1.46  kiyohara #include <powerpc/ibm4xx/dcr4xx.h>
    110       1.1       scw 
    111      1.54      matt #include <powerpc/ibm4xx/pci_machdep.h>
    112      1.54      matt 
    113      1.53      matt #include <powerpc/pic/picvar.h>
    114      1.53      matt 
    115       1.1       scw #include <dev/cons.h>
    116      1.46  kiyohara #include <dev/pci/pcivar.h>
    117      1.46  kiyohara #include <dev/pci/pciconf.h>
    118       1.1       scw 
    119       1.9     ragge #include "ksyms.h"
    120       1.9     ragge 
    121       1.9     ragge #if defined(DDB)
    122      1.52      matt #include <powerpc/db_machdep.h>
    123       1.1       scw #include <ddb/db_extern.h>
    124       1.1       scw #endif
    125       1.1       scw 
    126      1.30  kiyohara 
    127      1.30  kiyohara #define TLB_PG_SIZE 	(16*1024*1024)
    128      1.30  kiyohara 
    129       1.1       scw /*
    130       1.1       scw  * Global variables used here and there
    131       1.1       scw  */
    132       1.1       scw struct vm_map *phys_map = NULL;
    133       1.1       scw 
    134       1.1       scw /*
    135       1.1       scw  * This should probably be in autoconf!				XXX
    136       1.1       scw  */
    137       1.1       scw char machine[] = MACHINE;		/* from <machine/param.h> */
    138       1.1       scw char machine_arch[] = MACHINE_ARCH;	/* from <machine/param.h> */
    139       1.1       scw 
    140       1.1       scw char bootpath[256];
    141       1.1       scw 
    142      1.53      matt void initppc(vaddr_t, vaddr_t, char *, void *);
    143       1.1       scw 
    144       1.1       scw static void dumpsys(void);
    145       1.1       scw 
    146       1.1       scw #define MEMREGIONS	8
    147       1.1       scw struct mem_region physmemr[MEMREGIONS];		/* Hard code memory */
    148       1.1       scw struct mem_region availmemr[MEMREGIONS];	/* Who's supposed to set these up? */
    149       1.1       scw 
    150       1.1       scw struct board_cfg_data board_data;
    151       1.1       scw 
    152       1.1       scw void
    153      1.53      matt initppc(vaddr_t startkernel, vaddr_t endkernel, char *args, void *info_block)
    154       1.1       scw {
    155       1.1       scw 	/* Disable all external interrupts */
    156      1.46  kiyohara 	mtdcr(DCR_UIC0_BASE + DCR_UIC_ER, 0);
    157       1.1       scw 
    158       1.1       scw         /* Initialize cache info for memcpy, etc. */
    159       1.1       scw         cpu_probe_cache();
    160       1.1       scw 
    161       1.1       scw 	/* Save info block */
    162       1.1       scw 	memcpy(&board_data, info_block, sizeof(board_data));
    163       1.1       scw 
    164       1.1       scw 	memset(physmemr, 0, sizeof physmemr);
    165       1.1       scw 	memset(availmemr, 0, sizeof availmemr);
    166       1.1       scw 	physmemr[0].start = 0;
    167       1.1       scw 	physmemr[0].size = board_data.mem_size & ~PGOFSET;
    168       1.1       scw 	/* Lower memory reserved by eval board BIOS */
    169      1.46  kiyohara 	availmemr[0].start = startkernel;
    170       1.1       scw 	availmemr[0].size = board_data.mem_size - availmemr[0].start;
    171       1.1       scw 
    172      1.31     freza 	/* Linear map kernel memory */
    173      1.53      matt 	for (vaddr_t va = 0; va < endkernel; va += TLB_PG_SIZE) {
    174      1.30  kiyohara 		ppc4xx_tlb_reserve(va, va, TLB_PG_SIZE, TLB_EX);
    175      1.53      matt 	}
    176      1.30  kiyohara 
    177      1.31     freza 	/* Map console after physmem (see pmap_tlbmiss()) */
    178      1.31     freza 	ppc4xx_tlb_reserve(0xef000000, roundup(physmemr[0].size, TLB_PG_SIZE),
    179      1.31     freza 	    TLB_PG_SIZE, TLB_I | TLB_G);
    180      1.30  kiyohara 
    181      1.53      matt 	mtspr(SPR_TCR, 0);	/* disable all timers */
    182       1.1       scw 
    183      1.53      matt 	ibm4xx_init(startkernel, endkernel, pic_ext_intr);
    184       1.1       scw 
    185       1.1       scw #ifdef DEBUG
    186       1.1       scw 	printf("Board config data:\n");
    187       1.1       scw 	printf("  usr_config_ver = %s\n", board_data.usr_config_ver);
    188       1.1       scw 	printf("  rom_sw_ver = %s\n", board_data.rom_sw_ver);
    189       1.1       scw 	printf("  mem_size = %u\n", board_data.mem_size);
    190       1.1       scw 	printf("  mac_address_local = %02x:%02x:%02x:%02x:%02x:%02x\n",
    191       1.1       scw 	    board_data.mac_address_local[0], board_data.mac_address_local[1],
    192       1.1       scw 	    board_data.mac_address_local[2], board_data.mac_address_local[3],
    193       1.1       scw 	    board_data.mac_address_local[4], board_data.mac_address_local[5]);
    194       1.1       scw 	printf("  mac_address_pci = %02x:%02x:%02x:%02x:%02x:%02x\n",
    195       1.1       scw 	    board_data.mac_address_pci[0], board_data.mac_address_pci[1],
    196       1.1       scw 	    board_data.mac_address_pci[2], board_data.mac_address_pci[3],
    197       1.1       scw 	    board_data.mac_address_pci[4], board_data.mac_address_pci[5]);
    198       1.1       scw 	printf("  processor_speed = %u\n", board_data.processor_speed);
    199       1.1       scw 	printf("  plb_speed = %u\n", board_data.plb_speed);
    200       1.1       scw 	printf("  pci_speed = %u\n", board_data.pci_speed);
    201       1.1       scw #endif
    202       1.1       scw 
    203       1.1       scw #ifdef DDB
    204       1.1       scw 	if (boothowto & RB_KDB)
    205       1.1       scw 		Debugger();
    206       1.1       scw #endif
    207       1.1       scw #ifdef IPKDB
    208       1.1       scw 	/*
    209       1.1       scw 	 * Now trap to IPKDB
    210       1.1       scw 	 */
    211       1.1       scw 	ipkdb_init();
    212       1.1       scw 	if (boothowto & RB_KDB)
    213       1.1       scw 		ipkdb_connect(0);
    214       1.1       scw #endif
    215      1.49       mrg 
    216      1.49       mrg 	/*
    217      1.49       mrg 	 * Look for the ibm4xx modules in the right place.
    218      1.49       mrg 	 */
    219      1.49       mrg 	module_machine = module_machine_ibm4xx;
    220       1.1       scw }
    221       1.1       scw 
    222       1.1       scw /*
    223       1.1       scw  * Machine dependent startup code.
    224       1.1       scw  */
    225       1.1       scw 
    226       1.1       scw void
    227       1.1       scw cpu_startup(void)
    228       1.1       scw {
    229       1.1       scw 	vaddr_t minaddr, maxaddr;
    230      1.27   thorpej 	prop_number_t pn;
    231      1.27   thorpej 	prop_data_t pd;
    232       1.1       scw 	char pbuf[9];
    233       1.1       scw 
    234       1.1       scw 	/*
    235       1.1       scw 	 * Initialize error message buffer (at end of core).
    236       1.1       scw 	 */
    237       1.1       scw #if 0	/* For some reason this fails... --Artem
    238       1.1       scw 	 * Besides, do we really have to put it at the end of core?
    239       1.1       scw 	 * Let's use static buffer for now
    240       1.1       scw 	 */
    241      1.22      yamt 	if (!(msgbuf_vaddr = uvm_km_alloc(kernel_map, round_page(MSGBUFSIZE), 0,
    242      1.22      yamt 	    UVM_KMF_VAONLY)))
    243       1.1       scw 		panic("startup: no room for message buffer");
    244       1.1       scw 	for (i = 0; i < btoc(MSGBUFSIZE); i++)
    245       1.8   thorpej 		pmap_kenter_pa(msgbuf_vaddr + i * PAGE_SIZE,
    246      1.41    cegger 		    msgbuf_paddr + i * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, 0);
    247      1.35  christos 	initmsgbuf((void *)msgbuf_vaddr, round_page(MSGBUFSIZE));
    248       1.1       scw #else
    249      1.35  christos 	initmsgbuf((void *)msgbuf, round_page(MSGBUFSIZE));
    250       1.1       scw #endif
    251       1.1       scw 
    252      1.23     lukem 	printf("%s%s", copyright, version);
    253       1.1       scw 	printf("Walnut PowerPC 405GP Evaluation Board\n");
    254       1.1       scw 
    255       1.1       scw 	format_bytes(pbuf, sizeof(pbuf), ctob(physmem));
    256       1.1       scw 	printf("total memory = %s\n", pbuf);
    257       1.1       scw 
    258       1.1       scw 	minaddr = 0;
    259       1.1       scw 	/*
    260       1.1       scw 	 * Allocate a submap for physio
    261       1.1       scw 	 */
    262       1.1       scw 	phys_map = uvm_km_suballoc(kernel_map, &minaddr, &maxaddr,
    263      1.34   thorpej 				 VM_PHYS_SIZE, 0, false, NULL);
    264       1.1       scw 
    265       1.1       scw 	/*
    266       1.1       scw 	 * No need to allocate an mbuf cluster submap.  Mbuf clusters
    267       1.1       scw 	 * are allocated via the pool allocator, and we use direct-mapped
    268       1.1       scw 	 * pool pages.
    269       1.1       scw 	 */
    270       1.1       scw 
    271       1.1       scw 	format_bytes(pbuf, sizeof(pbuf), ptoa(uvmexp.free));
    272       1.1       scw 	printf("avail memory = %s\n", pbuf);
    273       1.1       scw 
    274       1.1       scw 	/*
    275      1.27   thorpej 	 * Set up the board properties dictionary.
    276       1.1       scw 	 */
    277      1.27   thorpej 	board_properties = prop_dictionary_create();
    278      1.27   thorpej 	KASSERT(board_properties != NULL);
    279       1.1       scw 
    280      1.27   thorpej 	pn = prop_number_create_integer(board_data.mem_size);
    281      1.27   thorpej 	KASSERT(pn != NULL);
    282      1.34   thorpej 	if (prop_dictionary_set(board_properties, "mem-size", pn) == false)
    283       1.1       scw 		panic("setting mem-size");
    284      1.27   thorpej 	prop_object_release(pn);
    285      1.27   thorpej 
    286      1.27   thorpej 	pd = prop_data_create_data_nocopy(board_data.mac_address_local,
    287      1.27   thorpej 					  sizeof(board_data.mac_address_local));
    288      1.27   thorpej 	KASSERT(pd != NULL);
    289      1.27   thorpej 	if (prop_dictionary_set(board_properties, "emac0-mac-addr",
    290      1.34   thorpej 				pd) == false)
    291      1.26   thorpej 		panic("setting emac0-mac-addr");
    292      1.27   thorpej 	prop_object_release(pd);
    293      1.27   thorpej 
    294      1.27   thorpej 	pd = prop_data_create_data_nocopy(board_data.mac_address_pci,
    295      1.27   thorpej 					  sizeof(board_data.mac_address_pci));
    296      1.27   thorpej 	KASSERT(pd != NULL);
    297      1.27   thorpej 	if (prop_dictionary_set(board_properties, "sip0-mac-addr",
    298      1.34   thorpej 				pd) == false)
    299       1.1       scw 		panic("setting sip0-mac-addr");
    300      1.27   thorpej 	prop_object_release(pd);
    301      1.27   thorpej 
    302      1.27   thorpej 	pn = prop_number_create_integer(board_data.processor_speed);
    303      1.27   thorpej 	KASSERT(pn != NULL);
    304      1.27   thorpej 	if (prop_dictionary_set(board_properties, "processor-frequency",
    305      1.34   thorpej 				pn) == false)
    306       1.1       scw 		panic("setting processor-frequency");
    307      1.27   thorpej 	prop_object_release(pn);
    308      1.16       scw 
    309      1.16       scw 	/*
    310      1.16       scw 	 * Now that we have VM, malloc()s are OK in bus_space.
    311      1.16       scw 	 */
    312      1.16       scw 	bus_space_mallocok();
    313      1.16       scw 	fake_mapiodev = 0;
    314       1.1       scw }
    315       1.1       scw 
    316       1.1       scw 
    317       1.1       scw static void
    318       1.1       scw dumpsys(void)
    319       1.1       scw {
    320       1.1       scw 
    321       1.1       scw 	printf("dumpsys: TBD\n");
    322       1.1       scw }
    323       1.1       scw 
    324       1.1       scw /*
    325       1.1       scw  * Halt or reboot the machine after syncing/dumping according to howto.
    326       1.1       scw  */
    327       1.1       scw void
    328       1.1       scw cpu_reboot(int howto, char *what)
    329       1.1       scw {
    330       1.1       scw 	static int syncing;
    331       1.1       scw 	static char str[256];
    332       1.1       scw 	char *ap = str, *ap1 = ap;
    333       1.1       scw 
    334       1.1       scw 	boothowto = howto;
    335       1.1       scw 	if (!cold && !(howto & RB_NOSYNC) && !syncing) {
    336       1.1       scw 		syncing = 1;
    337       1.1       scw 		vfs_shutdown();		/* sync */
    338       1.1       scw 		resettodr();		/* set wall clock */
    339       1.1       scw 	}
    340       1.1       scw 
    341       1.1       scw 	splhigh();
    342       1.1       scw 
    343       1.1       scw 	if (!cold && (howto & RB_DUMP))
    344       1.1       scw 		dumpsys();
    345       1.1       scw 
    346       1.1       scw 	doshutdownhooks();
    347       1.1       scw 
    348      1.37    dyoung 	pmf_system_shutdown(boothowto);
    349      1.37    dyoung 
    350       1.1       scw 	if ((howto & RB_POWERDOWN) == RB_POWERDOWN) {
    351       1.1       scw 	  /* Power off here if we know how...*/
    352       1.1       scw 	}
    353       1.1       scw 
    354       1.1       scw 	if (howto & RB_HALT) {
    355       1.1       scw 		printf("halted\n\n");
    356       1.1       scw 
    357       1.1       scw 		goto reboot;	/* XXX for now... */
    358       1.1       scw 
    359       1.1       scw #ifdef DDB
    360       1.1       scw 		printf("dropping to debugger\n");
    361       1.1       scw 		while(1)
    362       1.1       scw 			Debugger();
    363       1.1       scw #endif
    364       1.1       scw 	}
    365       1.1       scw 
    366       1.1       scw 	printf("rebooting\n\n");
    367       1.1       scw 	if (what && *what) {
    368       1.1       scw 		if (strlen(what) > sizeof str - 5)
    369       1.1       scw 			printf("boot string too large, ignored\n");
    370       1.1       scw 		else {
    371       1.1       scw 			strcpy(str, what);
    372       1.1       scw 			ap1 = ap = str + strlen(str);
    373       1.1       scw 			*ap++ = ' ';
    374       1.1       scw 		}
    375       1.1       scw 	}
    376       1.1       scw 	*ap++ = '-';
    377       1.1       scw 	if (howto & RB_SINGLE)
    378       1.1       scw 		*ap++ = 's';
    379       1.1       scw 	if (howto & RB_KDB)
    380       1.1       scw 		*ap++ = 'd';
    381       1.1       scw 	*ap++ = 0;
    382       1.1       scw 	if (ap[-2] == '-')
    383       1.1       scw 		*ap1 = 0;
    384       1.1       scw 
    385       1.1       scw 	/* flush cache for msgbuf */
    386       1.1       scw 	__syncicache((void *)msgbuf_paddr, round_page(MSGBUFSIZE));
    387       1.1       scw 
    388       1.1       scw  reboot:
    389       1.1       scw 	ppc4xx_reset();
    390       1.1       scw 
    391       1.1       scw 	printf("ppc4xx_reset() failed!\n");
    392       1.1       scw #ifdef DDB
    393       1.1       scw 	while(1)
    394       1.1       scw 		Debugger();
    395       1.1       scw #else
    396       1.1       scw 	while (1)
    397       1.1       scw 		/* nothing */;
    398       1.1       scw #endif
    399       1.1       scw }
    400       1.1       scw 
    401       1.1       scw void
    402       1.1       scw mem_regions(struct mem_region **mem, struct mem_region **avail)
    403       1.1       scw {
    404       1.1       scw 
    405       1.1       scw 	*mem = physmemr;
    406       1.1       scw 	*avail = availmemr;
    407       1.1       scw }
    408      1.46  kiyohara 
    409      1.46  kiyohara 
    410      1.46  kiyohara int
    411      1.54      matt ibm4xx_pci_bus_maxdevs(void *v, int busno)
    412      1.46  kiyohara {
    413      1.46  kiyohara 
    414      1.46  kiyohara 	/*
    415      1.46  kiyohara 	 * Bus number is irrelevant.  Configuration Mechanism 1 is in
    416      1.46  kiyohara 	 * use, can have devices 0-32 (i.e. the `normal' range).
    417      1.46  kiyohara 	 */
    418      1.46  kiyohara 	return 5;
    419      1.46  kiyohara }
    420      1.46  kiyohara 
    421      1.46  kiyohara int
    422      1.54      matt ibm4xx_pci_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *ihp)
    423      1.46  kiyohara {
    424      1.46  kiyohara 	int pin = pa->pa_intrpin;
    425      1.46  kiyohara 	int dev = pa->pa_device;
    426      1.46  kiyohara 
    427      1.46  kiyohara 	if (pin == 0)
    428      1.46  kiyohara 		/* No IRQ used. */
    429      1.46  kiyohara 		goto bad;
    430      1.46  kiyohara 
    431      1.46  kiyohara 	if (pin > 4) {
    432      1.54      matt 		printf("%s: bad interrupt pin %d\n", __func__, pin);
    433      1.46  kiyohara 		goto bad;
    434      1.46  kiyohara 	}
    435      1.46  kiyohara 
    436      1.46  kiyohara 	/*
    437      1.46  kiyohara 	 * We need to map the interrupt pin to the interrupt bit in the UIC
    438      1.46  kiyohara 	 * associated with it.  This is highly machine-dependent.
    439      1.46  kiyohara 	 */
    440      1.46  kiyohara 	switch(dev) {
    441      1.46  kiyohara 	case 1:
    442      1.46  kiyohara 	case 2:
    443      1.46  kiyohara 	case 3:
    444      1.46  kiyohara 	case 4:
    445      1.46  kiyohara 		*ihp = 27 + dev;
    446      1.46  kiyohara 		break;
    447      1.46  kiyohara 	default:
    448      1.46  kiyohara 		printf("Hmm.. PCI device %d should not exist on this board\n",
    449      1.46  kiyohara 			dev);
    450      1.46  kiyohara 		goto bad;
    451      1.46  kiyohara 	}
    452      1.46  kiyohara 	return 0;
    453      1.46  kiyohara 
    454      1.46  kiyohara bad:
    455      1.46  kiyohara 	*ihp = -1;
    456      1.46  kiyohara 	return 1;
    457      1.46  kiyohara }
    458      1.46  kiyohara 
    459      1.46  kiyohara void
    460      1.54      matt ibm4xx_pci_conf_interrupt(void *v, int bus, int dev, int pin, int swiz,
    461      1.54      matt     int *iline)
    462      1.46  kiyohara {
    463      1.46  kiyohara 
    464      1.54      matt 	if (bus == 0) {
    465      1.46  kiyohara 		switch(dev) {
    466      1.46  kiyohara 		case 1:
    467      1.46  kiyohara 		case 2:
    468      1.46  kiyohara 		case 3:
    469      1.46  kiyohara 		case 4:
    470      1.46  kiyohara 			*iline = 31 - dev;
    471      1.46  kiyohara 		}
    472      1.54      matt 	} else
    473      1.46  kiyohara 		*iline = 20 + ((swiz + dev + 1) & 3);
    474      1.46  kiyohara }
    475