1/**
2 * \file
3 * \brief ARM Cortex A9 Snoop Control Unit (SCU) driver.
4 */
5
6/*
7 * Copyright (c) 2015 ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
13 */
14#include <a9_scu.h>
15#include <kernel.h>
16#include <paging_kernel_arch.h>
17#include <dev/cortex_a9_scu_dev.h>
18
19//
20// We only have one SCU.
21//
22static cortex_a9_scu_t scu;
23static bool initialized = false;
24
25//
26// The SCU is not very big...
27//
28#define SCU_SIZE 0x100
29
30#define MSG(format, ...) printk( LOG_NOTE, "CortexA9 SCU: "format, ## __VA_ARGS__ )
31
32/**
33 * Initialize the SCU to be found at physical address 'pa'
34 */
35void a9_scu_init( lpaddr_t pa )
36{
37    assert( !initialized );
38    lvaddr_t scu_base = paging_map_device(pa, SCU_SIZE);
39    cortex_a9_scu_initialize(&scu, (mackerel_addr_t)scu_base);
40    MSG("initialized at 0x%"PRIxLVADDR"\n", scu_base);
41    initialized = true;
42}
43
44/**
45 * Print out the SCU contents
46 */
47void a9_scu_print(void)
48{
49    assert( initialized );
50    char buf[ 1024 ];
51    cortex_a9_scu_pr( buf, 1024, &scu );
52    printf("%s\n", buf);
53}
54
55/**
56 * Enable the SCU.  Must have been initialized.
57 */
58void a9_scu_enable(void)
59{
60    assert( initialized );
61    cortex_a9_scu_control_enable_wrf(&scu, 1);
62    // (should invalidate d-cache here?)
63
64}
65
66/**
67 * Return the core count.
68 */
69size_t a9_scu_core_count(void)
70{
71    assert( initialized );
72    return cortex_a9_scu_config_numcpus_rdf(&scu) + 1;
73}
74