cci400.c 2.41 KB
Newer Older
1
/*
2
 * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
3
 *
dp-arm's avatar
dp-arm committed
4
 * SPDX-License-Identifier: BSD-3-Clause
5
6
 */

7
8
#include <arch.h>
#include <assert.h>
9
#include <cci400.h>
10
#include <debug.h>
11
#include <mmio.h>
12
#include <stdint.h>
13
14
15

#define MAX_CLUSTERS		2

16
static uintptr_t cci_base_addr;
17
18
19
static unsigned int cci_cluster_ix_to_iface[MAX_CLUSTERS];


20
void cci_init(uintptr_t cci_base,
21
22
23
24
25
26
		int slave_iface3_cluster_ix,
		int slave_iface4_cluster_ix)
{
	/*
	 * Check the passed arguments are valid. The cluster indices must be
	 * less than MAX_CLUSTERS, not the same as each other and at least one
27
	 * of them must refer to a valid cluster index.
28
29
30
31
32
33
	 */
	assert(cci_base);
	assert(slave_iface3_cluster_ix < MAX_CLUSTERS);
	assert(slave_iface4_cluster_ix < MAX_CLUSTERS);
	assert(slave_iface3_cluster_ix != slave_iface4_cluster_ix);
	assert((slave_iface3_cluster_ix >= 0) ||
34
		(slave_iface4_cluster_ix >= 0));
35

36
37
38
	WARN("Please migrate to common cci driver, This driver will be" \
		" deprecated in future\n");

39
40
41
42
43
44
45
46
	cci_base_addr = cci_base;
	if (slave_iface3_cluster_ix >= 0)
		cci_cluster_ix_to_iface[slave_iface3_cluster_ix] =
			SLAVE_IFACE3_OFFSET;
	if (slave_iface4_cluster_ix >= 0)
		cci_cluster_ix_to_iface[slave_iface4_cluster_ix] =
			SLAVE_IFACE4_OFFSET;
}
47
48
49

static inline unsigned long get_slave_iface_base(unsigned long mpidr)
{
50
51
52
53
54
55
56
57
58
59
60
61
62
	/*
	 * We assume the TF topology code allocates affinity instances
	 * consecutively from zero.
	 * It is a programming error if this is called without initializing
	 * the slave interface to use for this cluster.
	 */
	unsigned int cluster_id =
		(mpidr >> MPIDR_AFF1_SHIFT) & MPIDR_AFFLVL_MASK;

	assert(cluster_id < MAX_CLUSTERS);
	assert(cci_cluster_ix_to_iface[cluster_id] != 0);

	return cci_base_addr + cci_cluster_ix_to_iface[cluster_id];
63
64
}

65
void cci_enable_cluster_coherency(unsigned long mpidr)
66
{
67
	assert(cci_base_addr);
68
69
70
71
72
	/* Enable Snoops and DVM messages */
	mmio_write_32(get_slave_iface_base(mpidr) + SNOOP_CTRL_REG,
		      DVM_EN_BIT | SNOOP_EN_BIT);

	/* Wait for the dust to settle down */
73
	while (mmio_read_32(cci_base_addr + STATUS_REG) & CHANGE_PENDING_BIT)
74
		;
75
76
}

77
void cci_disable_cluster_coherency(unsigned long mpidr)
78
{
79
	assert(cci_base_addr);
80
81
82
83
84
	/* Disable Snoops and DVM messages */
	mmio_write_32(get_slave_iface_base(mpidr) + SNOOP_CTRL_REG,
		      ~(DVM_EN_BIT | SNOOP_EN_BIT));

	/* Wait for the dust to settle down */
85
	while (mmio_read_32(cci_base_addr + STATUS_REG) & CHANGE_PENDING_BIT)
86
		;
87
88
}