1239281Sgonzo/*-
2239281Sgonzo * Copyright (c) 2012 Olivier Houchard.  All rights reserved.
3239281Sgonzo *
4239281Sgonzo * Redistribution and use in source and binary forms, with or without
5239281Sgonzo * modification, are permitted provided that the following conditions
6239281Sgonzo * are met:
7239281Sgonzo * 1. Redistributions of source code must retain the above copyright
8239281Sgonzo *    notice, this list of conditions and the following disclaimer.
9239281Sgonzo * 2. Redistributions in binary form must reproduce the above copyright
10239281Sgonzo *    notice, this list of conditions and the following disclaimer in the
11239281Sgonzo *    documentation and/or other materials provided with the distribution.
12239281Sgonzo *
13239281Sgonzo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14239281Sgonzo * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15239281Sgonzo * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16239281Sgonzo * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17239281Sgonzo * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18239281Sgonzo * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19239281Sgonzo * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20239281Sgonzo * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21239281Sgonzo * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22239281Sgonzo * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23239281Sgonzo */
24239281Sgonzo
25239281Sgonzo#include <sys/cdefs.h>
26239281Sgonzo__FBSDID("$FreeBSD$");
27239281Sgonzo#include <sys/types.h>
28239281Sgonzo#include <sys/param.h>
29239281Sgonzo#include <sys/systm.h>
30244914Sgonzo#include <sys/bus.h>
31244914Sgonzo#include <sys/rman.h>
32244914Sgonzo#include <sys/lock.h>
33244914Sgonzo#include <sys/mutex.h>
34244914Sgonzo
35239281Sgonzo#include <arm/ti/ti_smc.h>
36239281Sgonzo#include <arm/ti/omap4/omap4_smc.h>
37244914Sgonzo#include <machine/bus.h>
38239281Sgonzo#include <machine/pl310.h>
39239281Sgonzo
40239281Sgonzovoid
41244914Sgonzoplatform_pl310_init(struct pl310_softc *sc)
42239281Sgonzo{
43244914Sgonzo	uint32_t aux, prefetch;
44244914Sgonzo
45244914Sgonzo	aux = pl310_read4(sc, PL310_AUX_CTRL);
46244914Sgonzo	prefetch = pl310_read4(sc, PL310_PREFETCH_CTRL);
47244914Sgonzo
48244914Sgonzo	/*
49244914Sgonzo	 * Disable instruction prefetch
50244914Sgonzo	 */
51244914Sgonzo	prefetch &= ~PREFETCH_CTRL_INSTR_PREFETCH;
52244914Sgonzo	aux &= ~AUX_CTRL_INSTR_PREFETCH;
53244914Sgonzo
54244914Sgonzo	// prefetch &= ~PREFETCH_CTRL_DATA_PREFETCH;
55244914Sgonzo	// aux &= ~AUX_CTRL_DATA_PREFETCH;
56244914Sgonzo
57244914Sgonzo	/*
58244914Sgonzo	 * Make sure data prefetch is on
59244914Sgonzo	 */
60244914Sgonzo	prefetch |= PREFETCH_CTRL_DATA_PREFETCH;
61244914Sgonzo	aux |= AUX_CTRL_DATA_PREFETCH;
62244914Sgonzo
63244914Sgonzo	/*
64244914Sgonzo	 * TODO: add tunable for prefetch offset
65244914Sgonzo	 * and experiment with performance
66244914Sgonzo	 */
67244914Sgonzo
68244914Sgonzo	ti_smc0(aux, 0, WRITE_AUXCTRL_REG);
69244914Sgonzo	ti_smc0(prefetch, 0, WRITE_PREFETCH_CTRL_REG);
70239281Sgonzo}
71239281Sgonzo
72244914Sgonzovoid
73244914Sgonzoplatform_pl310_write_ctrl(struct pl310_softc *sc, uint32_t val)
74244914Sgonzo{
75244914Sgonzo	ti_smc0(val, 0, L2CACHE_WRITE_CTRL_REG);
76244914Sgonzo}
77244914Sgonzo
78244914Sgonzovoid
79244914Sgonzoplatform_pl310_write_debug(struct pl310_softc *sc, uint32_t val)
80244914Sgonzo{
81244914Sgonzo	ti_smc0(val, 0, L2CACHE_WRITE_DEBUG_REG);
82244914Sgonzo}
83