xref: /netbsd-src/sys/arch/evbarm/fdt/fdt_bus_machdep.c (revision 8d564c5dcfeea024762586ce07de3c286d3d30e1)
1*8d564c5dSskrll /* $NetBSD: fdt_bus_machdep.c,v 1.3 2023/04/07 08:55:31 skrll Exp $ */
277a7b674Sjmcneill 
377a7b674Sjmcneill /*-
477a7b674Sjmcneill  * Copyright (c) 2021 Jared McNeill <jmcneill@invisible.ca>
577a7b674Sjmcneill  * All rights reserved.
677a7b674Sjmcneill  *
777a7b674Sjmcneill  * Redistribution and use in source and binary forms, with or without
877a7b674Sjmcneill  * modification, are permitted provided that the following conditions
977a7b674Sjmcneill  * are met:
1077a7b674Sjmcneill  * 1. Redistributions of source code must retain the above copyright
1177a7b674Sjmcneill  *    notice, this list of conditions and the following disclaimer.
1277a7b674Sjmcneill  * 2. Redistributions in binary form must reproduce the above copyright
1377a7b674Sjmcneill  *    notice, this list of conditions and the following disclaimer in the
1477a7b674Sjmcneill  *    documentation and/or other materials provided with the distribution.
1577a7b674Sjmcneill  *
1677a7b674Sjmcneill  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1777a7b674Sjmcneill  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1877a7b674Sjmcneill  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1977a7b674Sjmcneill  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2077a7b674Sjmcneill  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2177a7b674Sjmcneill  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2277a7b674Sjmcneill  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2377a7b674Sjmcneill  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2477a7b674Sjmcneill  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2577a7b674Sjmcneill  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2677a7b674Sjmcneill  * SUCH DAMAGE.
2777a7b674Sjmcneill  */
2877a7b674Sjmcneill 
2977a7b674Sjmcneill #include <sys/cdefs.h>
30*8d564c5dSskrll __KERNEL_RCSID(0, "$NetBSD: fdt_bus_machdep.c,v 1.3 2023/04/07 08:55:31 skrll Exp $");
3177a7b674Sjmcneill 
3277a7b674Sjmcneill #include <sys/param.h>
3377a7b674Sjmcneill #include <sys/bus.h>
3477a7b674Sjmcneill #include <sys/kmem.h>
3577a7b674Sjmcneill 
3677a7b674Sjmcneill #include <dev/fdt/fdtvar.h>
37*8d564c5dSskrll 
3877a7b674Sjmcneill #include <arm/fdt/arm_fdtvar.h>
3977a7b674Sjmcneill 
4077a7b674Sjmcneill extern struct bus_space arm_generic_bs_tag;
4177a7b674Sjmcneill 
4277a7b674Sjmcneill static int
nonposted_mmio_bs_map(void * t,bus_addr_t bpa,bus_size_t size,int flag,bus_space_handle_t * bshp)4377a7b674Sjmcneill nonposted_mmio_bs_map(void *t, bus_addr_t bpa, bus_size_t size, int flag,
4477a7b674Sjmcneill     bus_space_handle_t *bshp)
4577a7b674Sjmcneill {
4677a7b674Sjmcneill 	if (flag == 0) {
475158b98cSjmcneill 		flag |= BUS_SPACE_MAP_NONPOSTED;
4877a7b674Sjmcneill 	}
4977a7b674Sjmcneill 
5077a7b674Sjmcneill 	return bus_space_map(&arm_generic_bs_tag, bpa, size, flag, bshp);
5177a7b674Sjmcneill }
5277a7b674Sjmcneill 
5377a7b674Sjmcneill bus_space_tag_t
fdtbus_bus_tag_create(int phandle,uint32_t flags)5477a7b674Sjmcneill fdtbus_bus_tag_create(int phandle, uint32_t flags)
5577a7b674Sjmcneill {
56*8d564c5dSskrll 	const struct fdt_platform *plat = fdt_platform_find();
5777a7b674Sjmcneill 	struct bus_space *tagp;
5877a7b674Sjmcneill 	struct fdt_attach_args faa;
5977a7b674Sjmcneill 
60*8d564c5dSskrll 	plat->fp_init_attach_args(&faa);
6177a7b674Sjmcneill 
6277a7b674Sjmcneill 	tagp = kmem_alloc(sizeof(*tagp), KM_SLEEP);
6377a7b674Sjmcneill 	*tagp = *faa.faa_bst;
6477a7b674Sjmcneill 	if ((flags & FDT_BUS_SPACE_FLAG_NONPOSTED_MMIO) != 0) {
6577a7b674Sjmcneill 		tagp->bs_map = nonposted_mmio_bs_map;
6677a7b674Sjmcneill 	}
6777a7b674Sjmcneill 
6877a7b674Sjmcneill 	return tagp;
6977a7b674Sjmcneill }
70