l2cc_fdt.c revision 1.1
11.1Shkenken/* $NetBSD: l2cc_fdt.c,v 1.1 2018/06/20 08:03:55 hkenken 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.1Shkenken__KERNEL_RCSID(0, "$NetBSD: l2cc_fdt.c,v 1.1 2018/06/20 08:03:55 hkenken 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.1Shkenkenstatic int 501.1Shkenkenl2cc_fdt_match(device_t parent, cfdata_t cf, void *aux) 511.1Shkenken{ 521.1Shkenken const char * const compatible[] = { 531.1Shkenken "arm,pl310-cache", 541.1Shkenken NULL 551.1Shkenken }; 561.1Shkenken struct fdt_attach_args * const faa = aux; 571.1Shkenken 581.1Shkenken return of_compatible(faa->faa_phandle, compatible) >= 0; 591.1Shkenken} 601.1Shkenken 611.1Shkenkenstatic void 621.1Shkenkenl2cc_fdt_attach(device_t parent, device_t self, void *aux) 631.1Shkenken{ 641.1Shkenken struct fdt_attach_args * const faa = aux; 651.1Shkenken const int phandle = faa->faa_phandle; 661.1Shkenken bus_space_handle_t bsh; 671.1Shkenken 681.1Shkenken bus_addr_t addr; 691.1Shkenken bus_size_t size; 701.1Shkenken if (fdtbus_get_reg(phandle, 0, &addr, &size) != 0) { 711.1Shkenken aprint_error(": couldn't get distributor address\n"); 721.1Shkenken return; 731.1Shkenken } 741.1Shkenken if (bus_space_map(faa->faa_bst, addr, size, 0, &bsh)) { 751.1Shkenken aprint_error(": couldn't map registers\n"); 761.1Shkenken return; 771.1Shkenken } 781.1Shkenken 791.1Shkenken struct mpcore_attach_args mpcaa = { 801.1Shkenken .mpcaa_name = "arml2cc", 811.1Shkenken .mpcaa_memt = faa->faa_bst, 821.1Shkenken .mpcaa_memh = bsh, 831.1Shkenken .mpcaa_off1 = 0, 841.1Shkenken .mpcaa_off2 = 0, 851.1Shkenken }; 861.1Shkenken 871.1Shkenken config_found(self, &mpcaa, NULL); 881.1Shkenken} 89