1 /*- 2 * Copyright (c) 2012 Semihalf. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27 #include "opt_platform.h" 28 29 #include <sys/param.h> 30 #include <sys/systm.h> 31 #include <sys/kernel.h> 32 #include <sys/bus.h> 33 #include <sys/proc.h> 34 #include <sys/pcpu.h> 35 #include <sys/rman.h> 36 #include <sys/sched.h> 37 38 #include <vm/vm.h> 39 #include <vm/pmap.h> 40 41 #include <machine/resource.h> 42 #include <machine/tlb.h> 43 44 #include "portals.h" 45 46 47 int 48 dpaa_portal_alloc_res(device_t dev, int cpu) 49 { 50 struct dpaa_portal_softc *sc = device_get_softc(dev); 51 52 sc->sc_mres[0] = bus_alloc_resource_any(dev, SYS_RES_MEMORY, 53 0, RF_ACTIVE); 54 if (sc->sc_mres[0] == NULL) { 55 device_printf(dev, 56 "Could not allocate cache enabled memory.\n"); 57 return (ENXIO); 58 } 59 /* Cache inhibited area */ 60 sc->sc_mres[1] = bus_alloc_resource_any(dev, SYS_RES_MEMORY, 61 1, RF_ACTIVE); 62 if (sc->sc_mres[1] == NULL) { 63 device_printf(dev, 64 "Could not allocate cache inhibited memory.\n"); 65 bus_release_resource(dev, SYS_RES_MEMORY, 0, sc->sc_mres[0]); 66 return (ENXIO); 67 } 68 sc->sc_dev = dev; 69 sc->sc_ce_va = rman_get_bushandle(sc->sc_mres[0]); 70 sc->sc_ce_size = rman_get_size(sc->sc_mres[0]); 71 sc->sc_ce_pa = pmap_kextract(sc->sc_ce_va); 72 sc->sc_ci_va = rman_get_bushandle(sc->sc_mres[1]); 73 sc->sc_ci_size = rman_get_size(sc->sc_mres[1]); 74 sc->sc_ci_pa = pmap_kextract(sc->sc_ci_va); 75 tlb1_set_entry(sc->sc_ce_va, sc->sc_ce_pa, sc->sc_ce_size, 76 _TLB_ENTRY_MEM | _TLB_ENTRY_SHARED); 77 sc->sc_ires = bus_alloc_resource_any(dev, SYS_RES_IRQ, 0, RF_ACTIVE); 78 79 /* Allocate interrupts */ 80 if (sc->sc_ires == NULL) { 81 device_printf(dev, "Could not allocate irq.\n"); 82 return (ENXIO); 83 } 84 85 return (0); 86 } 87