aboutsummaryrefslogtreecommitdiffstats
path: root/xen/arch/arm/platforms/vexpress.c
blob: b9d85af2abbf6c9b96ad025a21c811b2f9217111 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*
 * xen/arch/arm/platform_vexpress.c
 *
 * Versatile Express specific settings
 *
 * Stefano Stabellini <stefano.stabellini@eu.citrix.com>
 * Copyright (c) 2013 Citrix Systems.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#include <asm/platforms/vexpress.h>
#include <asm/platform.h>
#include <xen/mm.h>
#include <xen/vmap.h>
#include <asm/io.h>
#include <asm/gic.h>

#define DCC_SHIFT      26
#define FUNCTION_SHIFT 20
#define SITE_SHIFT     16
#define POSITION_SHIFT 12
#define DEVICE_SHIFT   0

static inline int vexpress_ctrl_start(uint32_t *syscfg, int write,
                                      int function, int device)
{
    int dcc = 0; /* DCC to access */
    int site = 0; /* motherboard */
    int position = 0; /* daughterboard */
    uint32_t stat;

    /* set control register */
    syscfg[V2M_SYS_CFGCTRL/4] = V2M_SYS_CFG_START |
        (write ? V2M_SYS_CFG_WRITE : 0) |
        (dcc << DCC_SHIFT) | (function << FUNCTION_SHIFT) |
        (site << SITE_SHIFT) | (position << POSITION_SHIFT) |
        (device << DEVICE_SHIFT);

    /* wait for complete flag to be set */
    do {
        stat = syscfg[V2M_SYS_CFGSTAT/4];
        dsb();
    } while ( !(stat & V2M_SYS_CFG_COMPLETE) );

    /* check error status and return error flag if set */
    if ( stat & V2M_SYS_CFG_ERROR )
    {
        printk(KERN_ERR "V2M SYS_CFGSTAT reported a configuration error\n");
        return -1;
    }
    return 0;
}

int vexpress_syscfg(int write, int function, int device, uint32_t *data)
{
    uint32_t *syscfg = (uint32_t *) FIXMAP_ADDR(FIXMAP_MISC);
    int ret = -1;

    set_fixmap(FIXMAP_MISC, V2M_SYS_MMIO_BASE >> PAGE_SHIFT, DEV_SHARED);

    if ( syscfg[V2M_SYS_CFGCTRL/4] & V2M_SYS_CFG_START )
        goto out;

    /* clear the complete bit in the V2M_SYS_CFGSTAT status register */
    syscfg[V2M_SYS_CFGSTAT/4] = 0;

    if ( write )
    {
        /* write data */
        syscfg[V2M_SYS_CFGDATA/4] = *data;

        if ( vexpress_ctrl_start(syscfg, write, function, device) < 0 )
            goto out;
    } else {
        if ( vexpress_ctrl_start(syscfg, write, function, device) < 0 )
            goto out;
        else
            /* read data */
            *data = syscfg[V2M_SYS_CFGDATA/4];
    }

    ret = 0;
out:
    clear_fixmap(FIXMAP_MISC);
    return ret;
}

/*
 * TODO: Get base address from the device tree
 * See arm,vexpress-reset node
 */
static void vexpress_reset(void)
{
    void __iomem *sp810;

    /* Use the SP810 system controller to force a reset */
    sp810 = ioremap_nocache(SP810_ADDRESS, PAGE_SIZE);

    if ( !sp810 )
    {
        dprintk(XENLOG_ERR, "Unable to map SP810\n");
        return;
    }

    /* switch to slow mode */
    writel(0x3, sp810);
    dsb(); isb();
    /* writing any value to SCSYSSTAT reg will reset the system */
    writel(0x1, sp810 + 4);
    dsb(); isb();

    iounmap(sp810);
}

#ifdef CONFIG_ARM_32

static int __init vexpress_smp_init(void)
{
    void __iomem *sysflags;

    sysflags = ioremap_nocache(V2M_SYS_MMIO_BASE, PAGE_SIZE);
    if ( !sysflags )
    {
        dprintk(XENLOG_ERR, "Unable to map vexpress MMIO\n");
        return -EFAULT;
    }

    printk("Set SYS_FLAGS to %"PRIpaddr" (%p)\n",
           __pa(init_secondary), init_secondary);
    writel(~0, sysflags + V2M_SYS_FLAGSCLR);
    writel(__pa(init_secondary), sysflags + V2M_SYS_FLAGSSET);

    iounmap(sysflags);

    return 0;
}

static int __init vexpress_cpu_up(int cpu)
{
    /* Nothing to do here, the generic sev() will suffice to kick CPUs
     * out of either the firmware or our own smp_up_cpu gate,
     * depending on where they have ended up. */

    return 0;
}
#endif

static const char * const vexpress_dt_compat[] __initdata =
{
    "arm,vexpress",
    NULL
};

static const struct dt_device_match vexpress_blacklist_dev[] __initconst =
{
    /* Cache Coherent Interconnect */
    DT_MATCH_COMPATIBLE("arm,cci-400"),
    DT_MATCH_COMPATIBLE("arm,cci-400-pmu"),
    /* Video device
     * TODO: remove it once memreserve is handled properly by Xen
     */
    DT_MATCH_COMPATIBLE("arm,hdlcd"),
    /* Hardware power management */
    DT_MATCH_COMPATIBLE("arm,vexpress-reset"),
    DT_MATCH_COMPATIBLE("arm,vexpress-reboot"),
    DT_MATCH_COMPATIBLE("arm,vexpress-shutdown"),
    { /* sentinel */ },
};

PLATFORM_START(vexpress, "VERSATILE EXPRESS")
    .compatible = vexpress_dt_compat,
#ifdef CONFIG_ARM_32
    .smp_init = vexpress_smp_init,
    .cpu_up = vexpress_cpu_up,
#endif
    .reset = vexpress_reset,
    .blacklist_dev = vexpress_blacklist_dev,
PLATFORM_END

/*
 * Local variables:
 * mode: C
 * c-file-style: "BSD"
 * c-basic-offset: 4
 * indent-tabs-mode: nil
 * End:
 */