xref: /netbsd-src/sys/arch/emips/ebus/ebus.c (revision c7fb772b85b2b5d4cfb282f868f454b4701534fd)
1*c7fb772bSthorpej /*	$NetBSD: ebus.c,v 1.4 2021/08/07 16:18:48 thorpej Exp $	*/
25f7e80a8Spooka 
35f7e80a8Spooka /*-
45f7e80a8Spooka  * Copyright (c) 2010 The NetBSD Foundation, Inc.
55f7e80a8Spooka  * All rights reserved.
65f7e80a8Spooka  *
75f7e80a8Spooka  * This code was written by Alessandro Forin and Neil Pittman
85f7e80a8Spooka  * at Microsoft Research and contributed to The NetBSD Foundation
95f7e80a8Spooka  * by Microsoft Corporation.
105f7e80a8Spooka  *
115f7e80a8Spooka  * Redistribution and use in source and binary forms, with or without
125f7e80a8Spooka  * modification, are permitted provided that the following conditions
135f7e80a8Spooka  * are met:
145f7e80a8Spooka  * 1. Redistributions of source code must retain the above copyright
155f7e80a8Spooka  *    notice, this list of conditions and the following disclaimer.
165f7e80a8Spooka  * 2. Redistributions in binary form must reproduce the above copyright
175f7e80a8Spooka  *    notice, this list of conditions and the following disclaimer in the
185f7e80a8Spooka  *    documentation and/or other materials provided with the distribution.
195f7e80a8Spooka  *
205f7e80a8Spooka  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
215f7e80a8Spooka  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
225f7e80a8Spooka  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
235f7e80a8Spooka  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
245f7e80a8Spooka  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
255f7e80a8Spooka  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
265f7e80a8Spooka  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
275f7e80a8Spooka  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
285f7e80a8Spooka  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
295f7e80a8Spooka  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
305f7e80a8Spooka  * POSSIBILITY OF SUCH DAMAGE.
315f7e80a8Spooka  */
325f7e80a8Spooka 
335f7e80a8Spooka #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
34*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: ebus.c,v 1.4 2021/08/07 16:18:48 thorpej Exp $");
355f7e80a8Spooka 
365f7e80a8Spooka #include <sys/param.h>
375f7e80a8Spooka #include <sys/systm.h>
385f7e80a8Spooka #include <sys/device.h>
395f7e80a8Spooka 
405f7e80a8Spooka #include <machine/sysconf.h>
415f7e80a8Spooka #include <emips/ebus/ebusvar.h>
425f7e80a8Spooka #include <emips/emips/machdep.h>
435f7e80a8Spooka 
445f7e80a8Spooka #include "locators.h"
455f7e80a8Spooka 
465f7e80a8Spooka void
ebusattach(device_t parent,device_t self,void * aux)47bd817f5fStsutsui ebusattach(device_t parent, device_t self, void *aux)
485f7e80a8Spooka {
495f7e80a8Spooka 	struct ebus_dev_attach_args *ida = aux;
505f7e80a8Spooka 	struct ebus_attach_args *ia;
515f7e80a8Spooka 	void *addr;
525f7e80a8Spooka 	int i;
535f7e80a8Spooka 	int locs[EBUSCF_NLOCS];
545f7e80a8Spooka 
555f7e80a8Spooka 	printf("\n");
565f7e80a8Spooka 
575f7e80a8Spooka 	/*
585f7e80a8Spooka 	 * Loop through the devices and attach them.  If a probe-size
595f7e80a8Spooka 	 * is specified, it's an optional item on the platform and
605f7e80a8Spooka 	 * do a badaddr() test to make sure it's there.
615f7e80a8Spooka 	 */
625f7e80a8Spooka 	for (i = 0; i < ida->ida_ndevs; i++) {
635f7e80a8Spooka 		ia = &ida->ida_devs[i];
645f7e80a8Spooka 
655f7e80a8Spooka #if 0 // DEBUG
66bd817f5fStsutsui 		printf("PROBING %s %d@%x i=%d\n",
67bd817f5fStsutsui 		    ia->ia_name, ia->ia_basz, ia->ia_paddr, ia->ia_cookie);
685f7e80a8Spooka #endif
695f7e80a8Spooka 		if (ia->ia_basz != 0) {
70bd817f5fStsutsui 			addr = (void *)mips_map_physmem(ia->ia_paddr,
71bd817f5fStsutsui 			    ia->ia_basz);
725f7e80a8Spooka 			if (addr == NULL) {
735f7e80a8Spooka 				printf("Failed to map %s: phys %x size %d\n",
745f7e80a8Spooka 				    ia->ia_name, ia->ia_paddr, ia->ia_basz);
755f7e80a8Spooka 				continue;
765f7e80a8Spooka 			}
775f7e80a8Spooka 			ia->ia_vaddr = addr;
785f7e80a8Spooka #if 0 // DEBUG
795f7e80a8Spooka 			printf("MAPPED at %p\n", ia->ia_vaddr);
805f7e80a8Spooka #endif
815f7e80a8Spooka 		}
825f7e80a8Spooka 
835f7e80a8Spooka 		locs[EBUSCF_ADDR] = ia->ia_paddr;
845f7e80a8Spooka 
852685996bSthorpej 		if (config_found(self, ia, ebusprint,
86*c7fb772bSthorpej 				 CFARGS(.submatch = config_stdsubmatch,
87*c7fb772bSthorpej 					.locators = locs)) == NULL) {
885f7e80a8Spooka 			/* do we need to say anything? */
895f7e80a8Spooka 			if (ia->ia_basz != 0) {
90bd817f5fStsutsui 				mips_unmap_physmem((vaddr_t)ia->ia_vaddr,
91bd817f5fStsutsui 				    ia->ia_basz);
925f7e80a8Spooka 			}
935f7e80a8Spooka 		}
945f7e80a8Spooka 	}
955f7e80a8Spooka }
965f7e80a8Spooka 
975f7e80a8Spooka int
ebusprint(void * aux,const char * pnp)98bd817f5fStsutsui ebusprint(void *aux, const char *pnp)
995f7e80a8Spooka {
1005f7e80a8Spooka 	struct ebus_attach_args *ia = aux;
1015f7e80a8Spooka 
1025f7e80a8Spooka 	if (pnp)
1035f7e80a8Spooka 		aprint_normal("%s at %s", ia->ia_name, pnp);
1045f7e80a8Spooka 
1055f7e80a8Spooka 	aprint_normal(" addr 0x%x", ia->ia_paddr);
1065f7e80a8Spooka 
107bd817f5fStsutsui 	return UNCONF;
1085f7e80a8Spooka }
1095f7e80a8Spooka 
1105f7e80a8Spooka void
ebus_intr_establish(device_t dev,void * cookie,int level,int (* handler)(void *,void *),void * arg)111bd817f5fStsutsui ebus_intr_establish(device_t dev, void *cookie, int level,
112bd817f5fStsutsui     int (*handler)(void *, void *), void *arg)
1135f7e80a8Spooka {
114bd817f5fStsutsui 
1155f7e80a8Spooka 	(*platform.intr_establish)(dev, cookie, level, handler, arg);
1165f7e80a8Spooka }
117