l2cc_fdt.c revision 1.3
11.3Sthorpej/* $NetBSD: l2cc_fdt.c,v 1.3 2021/01/27 03:10:19 thorpej Exp $ */ 21.1Shkenken/* 31.1Shkenken * Copyright (c) 2018 Genetec Corporation. All rights reserved. 41.1Shkenken * Written by Hashimoto Kenichi for Genetec Corporation. 51.1Shkenken * 61.1Shkenken * Redistribution and use in source and binary forms, with or without 71.1Shkenken * modification, are permitted provided that the following conditions 81.1Shkenken * are met: 91.1Shkenken * 1. Redistributions of source code must retain the above copyright 101.1Shkenken * notice, this list of conditions and the following disclaimer. 111.1Shkenken * 2. Redistributions in binary form must reproduce the above copyright 121.1Shkenken * notice, this list of conditions and the following disclaimer in the 131.1Shkenken * documentation and/or other materials provided with the distribution. 141.1Shkenken * 151.1Shkenken * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND 161.1Shkenken * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 171.1Shkenken * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 181.1Shkenken * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION 191.1Shkenken * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 201.1Shkenken * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 211.1Shkenken * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 221.1Shkenken * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 231.1Shkenken * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 241.1Shkenken * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 251.1Shkenken * POSSIBILITY OF SUCH DAMAGE. 261.1Shkenken */ 271.1Shkenken 281.1Shkenken#include <sys/cdefs.h> 291.3Sthorpej__KERNEL_RCSID(0, "$NetBSD: l2cc_fdt.c,v 1.3 2021/01/27 03:10:19 thorpej Exp $"); 301.1Shkenken 311.1Shkenken#include <sys/param.h> 321.1Shkenken#include <sys/bus.h> 331.1Shkenken#include <sys/device.h> 341.1Shkenken#include <sys/intr.h> 351.1Shkenken#include <sys/systm.h> 361.1Shkenken#include <sys/kernel.h> 371.1Shkenken#include <sys/kmem.h> 381.1Shkenken 391.1Shkenken#include <arm/cortex/mpcore_var.h> 401.1Shkenken 411.1Shkenken#include <dev/fdt/fdtvar.h> 421.1Shkenken#include <arm/fdt/arm_fdtvar.h> 431.1Shkenken 441.1Shkenkenstatic int l2cc_fdt_match(device_t, cfdata_t, void *); 451.1Shkenkenstatic void l2cc_fdt_attach(device_t, device_t, void *); 461.1Shkenken 471.1ShkenkenCFATTACH_DECL_NEW(l2cc_fdt, 0, l2cc_fdt_match, l2cc_fdt_attach, NULL, NULL); 481.1Shkenken 491.3Sthorpejstatic const struct device_compatible_entry compat_data[] = { 501.3Sthorpej { .compat = "arm,pl310-cache" }, 511.3Sthorpej DEVICE_COMPAT_EOL 521.3Sthorpej}; 531.3Sthorpej 541.1Shkenkenstatic int 551.1Shkenkenl2cc_fdt_match(device_t parent, cfdata_t cf, void *aux) 561.1Shkenken{ 571.1Shkenken struct fdt_attach_args * const faa = aux; 581.1Shkenken 591.3Sthorpej return of_compatible_match(faa->faa_phandle, compat_data); 601.1Shkenken} 611.1Shkenken 621.1Shkenkenstatic void 631.1Shkenkenl2cc_fdt_attach(device_t parent, device_t self, void *aux) 641.1Shkenken{ 651.1Shkenken struct fdt_attach_args * const faa = aux; 661.1Shkenken const int phandle = faa->faa_phandle; 671.1Shkenken bus_space_handle_t bsh; 681.1Shkenken 691.1Shkenken bus_addr_t addr; 701.1Shkenken bus_size_t size; 711.1Shkenken if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) { 721.1Shkenken aprint_error(": couldn't get distributor address\n"); 731.1Shkenken return; 741.1Shkenken } 751.1Shkenken if (bus_space_map(faa->faa_bst, addr, size, 0, &bsh)) { 761.1Shkenken aprint_error(": couldn't map registers\n"); 771.1Shkenken return; 781.1Shkenken } 791.1Shkenken 801.2Sjmcneill aprint_naive("\n"); 811.2Sjmcneill aprint_normal("\n"); 821.2Sjmcneill 831.1Shkenken struct mpcore_attach_args mpcaa = { 841.1Shkenken .mpcaa_name = "arml2cc", 851.1Shkenken .mpcaa_memt = faa->faa_bst, 861.1Shkenken .mpcaa_memh = bsh, 871.1Shkenken .mpcaa_off1 = 0, 881.1Shkenken .mpcaa_off2 = 0, 891.1Shkenken }; 901.1Shkenken 911.1Shkenken config_found(self, &mpcaa, NULL); 921.1Shkenken} 93