xref: /netbsd-src/sys/arch/arm/fdt/l2cc_fdt.c (revision c7fb772b85b2b5d4cfb282f868f454b4701534fd)
1*c7fb772bSthorpej /*	$NetBSD: l2cc_fdt.c,v 1.5 2021/08/07 16:18:43 thorpej Exp $	*/
209881193Shkenken /*
309881193Shkenken  * Copyright (c) 2018  Genetec Corporation.  All rights reserved.
409881193Shkenken  * Written by Hashimoto Kenichi for Genetec Corporation.
509881193Shkenken  *
609881193Shkenken  * Redistribution and use in source and binary forms, with or without
709881193Shkenken  * modification, are permitted provided that the following conditions
809881193Shkenken  * are met:
909881193Shkenken  * 1. Redistributions of source code must retain the above copyright
1009881193Shkenken  *    notice, this list of conditions and the following disclaimer.
1109881193Shkenken  * 2. Redistributions in binary form must reproduce the above copyright
1209881193Shkenken  *    notice, this list of conditions and the following disclaimer in the
1309881193Shkenken  *    documentation and/or other materials provided with the distribution.
1409881193Shkenken  *
1509881193Shkenken  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
1609881193Shkenken  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1709881193Shkenken  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1809881193Shkenken  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
1909881193Shkenken  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2009881193Shkenken  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2109881193Shkenken  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2209881193Shkenken  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2309881193Shkenken  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2409881193Shkenken  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2509881193Shkenken  * POSSIBILITY OF SUCH DAMAGE.
2609881193Shkenken  */
2709881193Shkenken 
2809881193Shkenken #include <sys/cdefs.h>
29*c7fb772bSthorpej __KERNEL_RCSID(0, "$NetBSD: l2cc_fdt.c,v 1.5 2021/08/07 16:18:43 thorpej Exp $");
3009881193Shkenken 
3109881193Shkenken #include <sys/param.h>
3209881193Shkenken #include <sys/bus.h>
3309881193Shkenken #include <sys/device.h>
3409881193Shkenken #include <sys/intr.h>
3509881193Shkenken #include <sys/systm.h>
3609881193Shkenken #include <sys/kernel.h>
3709881193Shkenken #include <sys/kmem.h>
3809881193Shkenken 
3909881193Shkenken #include <arm/cortex/mpcore_var.h>
4009881193Shkenken 
4109881193Shkenken #include <dev/fdt/fdtvar.h>
4209881193Shkenken #include <arm/fdt/arm_fdtvar.h>
4309881193Shkenken 
4409881193Shkenken static int l2cc_fdt_match(device_t, cfdata_t, void *);
4509881193Shkenken static void l2cc_fdt_attach(device_t, device_t, void *);
4609881193Shkenken 
4709881193Shkenken CFATTACH_DECL_NEW(l2cc_fdt, 0, l2cc_fdt_match, l2cc_fdt_attach, NULL, NULL);
4809881193Shkenken 
496e54367aSthorpej static const struct device_compatible_entry compat_data[] = {
506e54367aSthorpej 	{ .compat = "arm,pl310-cache" },
516e54367aSthorpej 	DEVICE_COMPAT_EOL
526e54367aSthorpej };
536e54367aSthorpej 
5409881193Shkenken static int
l2cc_fdt_match(device_t parent,cfdata_t cf,void * aux)5509881193Shkenken l2cc_fdt_match(device_t parent, cfdata_t cf, void *aux)
5609881193Shkenken {
5709881193Shkenken 	struct fdt_attach_args * const faa = aux;
5809881193Shkenken 
596e54367aSthorpej 	return of_compatible_match(faa->faa_phandle, compat_data);
6009881193Shkenken }
6109881193Shkenken 
6209881193Shkenken static void
l2cc_fdt_attach(device_t parent,device_t self,void * aux)6309881193Shkenken l2cc_fdt_attach(device_t parent, device_t self, void *aux)
6409881193Shkenken {
6509881193Shkenken 	struct fdt_attach_args * const faa = aux;
6609881193Shkenken 	const int phandle = faa->faa_phandle;
6709881193Shkenken 	bus_space_handle_t bsh;
6809881193Shkenken 
6909881193Shkenken 	bus_addr_t addr;
7009881193Shkenken 	bus_size_t size;
7109881193Shkenken 	if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) {
7209881193Shkenken 		aprint_error(": couldn't get distributor address\n");
7309881193Shkenken 		return;
7409881193Shkenken 	}
7509881193Shkenken 	if (bus_space_map(faa->faa_bst, addr, size, 0, &bsh)) {
7609881193Shkenken 		aprint_error(": couldn't map registers\n");
7709881193Shkenken 		return;
7809881193Shkenken 	}
7909881193Shkenken 
80912cfa14Sjmcneill 	aprint_naive("\n");
81912cfa14Sjmcneill 	aprint_normal("\n");
82912cfa14Sjmcneill 
8309881193Shkenken 	struct mpcore_attach_args mpcaa = {
8409881193Shkenken 		.mpcaa_name = "arml2cc",
8509881193Shkenken 		.mpcaa_memt = faa->faa_bst,
8609881193Shkenken 		.mpcaa_memh = bsh,
8709881193Shkenken 		.mpcaa_off1 = 0,
8809881193Shkenken 		.mpcaa_off2 = 0,
8909881193Shkenken 	};
9009881193Shkenken 
91*c7fb772bSthorpej 	config_found(self, &mpcaa, NULL, CFARGS_NONE);
9209881193Shkenken }
93