xref: /netbsd-src/sys/arch/arm/fdt/l2cc_fdt.c (revision c7fb772b85b2b5d4cfb282f868f454b4701534fd)
1 /*	$NetBSD: l2cc_fdt.c,v 1.5 2021/08/07 16:18:43 thorpej Exp $	*/
2 /*
3  * Copyright (c) 2018  Genetec Corporation.  All rights reserved.
4  * Written by Hashimoto Kenichi for Genetec Corporation.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
19  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: l2cc_fdt.c,v 1.5 2021/08/07 16:18:43 thorpej Exp $");
30 
31 #include <sys/param.h>
32 #include <sys/bus.h>
33 #include <sys/device.h>
34 #include <sys/intr.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/kmem.h>
38 
39 #include <arm/cortex/mpcore_var.h>
40 
41 #include <dev/fdt/fdtvar.h>
42 #include <arm/fdt/arm_fdtvar.h>
43 
44 static int l2cc_fdt_match(device_t, cfdata_t, void *);
45 static void l2cc_fdt_attach(device_t, device_t, void *);
46 
47 CFATTACH_DECL_NEW(l2cc_fdt, 0, l2cc_fdt_match, l2cc_fdt_attach, NULL, NULL);
48 
49 static const struct device_compatible_entry compat_data[] = {
50 	{ .compat = "arm,pl310-cache" },
51 	DEVICE_COMPAT_EOL
52 };
53 
54 static int
l2cc_fdt_match(device_t parent,cfdata_t cf,void * aux)55 l2cc_fdt_match(device_t parent, cfdata_t cf, void *aux)
56 {
57 	struct fdt_attach_args * const faa = aux;
58 
59 	return of_compatible_match(faa->faa_phandle, compat_data);
60 }
61 
62 static void
l2cc_fdt_attach(device_t parent,device_t self,void * aux)63 l2cc_fdt_attach(device_t parent, device_t self, void *aux)
64 {
65 	struct fdt_attach_args * const faa = aux;
66 	const int phandle = faa->faa_phandle;
67 	bus_space_handle_t bsh;
68 
69 	bus_addr_t addr;
70 	bus_size_t size;
71 	if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) {
72 		aprint_error(": couldn't get distributor address\n");
73 		return;
74 	}
75 	if (bus_space_map(faa->faa_bst, addr, size, 0, &bsh)) {
76 		aprint_error(": couldn't map registers\n");
77 		return;
78 	}
79 
80 	aprint_naive("\n");
81 	aprint_normal("\n");
82 
83 	struct mpcore_attach_args mpcaa = {
84 		.mpcaa_name = "arml2cc",
85 		.mpcaa_memt = faa->faa_bst,
86 		.mpcaa_memh = bsh,
87 		.mpcaa_off1 = 0,
88 		.mpcaa_off2 = 0,
89 	};
90 
91 	config_found(self, &mpcaa, NULL, CFARGS_NONE);
92 }
93