/* Is the operation region specified by address range? */ #define UNIPHIER_SSCOQM_S_IS_RANGE(op) \
((op & UNIPHIER_SSCOQM_S_MASK) == UNIPHIER_SSCOQM_S_RANGE)
/** * struct uniphier_cache_data - UniPhier outer cache specific data * * @ctrl_base: virtual base address of control registers * @rev_base: virtual base address of revision registers * @op_base: virtual base address of operation registers * @way_ctrl_base: virtual address of the way control registers for this * SoC revision * @way_mask: each bit specifies if the way is present * @nsets: number of associativity sets * @line_size: line size in bytes * @range_op_max_size: max size that can be handled by a single range operation * @list: list node to include this level in the whole cache hierarchy
*/ struct uniphier_cache_data { void __iomem *ctrl_base; void __iomem *rev_base; void __iomem *op_base; void __iomem *way_ctrl_base;
u32 way_mask;
u32 nsets;
u32 line_size;
u32 range_op_max_size; struct list_head list;
};
/* * List of the whole outer cache hierarchy. This list is only modified during * the early boot stage, so no mutex is taken for the access to the list.
*/ static LIST_HEAD(uniphier_cache_list);
/** * __uniphier_cache_sync - perform a sync point for a particular cache level * * @data: cache controller specific data
*/ staticvoid __uniphier_cache_sync(struct uniphier_cache_data *data)
{ /* This sequence need not be atomic. Do not disable IRQ. */
writel_relaxed(UNIPHIER_SSCOPE_CM_SYNC,
data->op_base + UNIPHIER_SSCOPE); /* need a read back to confirm */
readl_relaxed(data->op_base + UNIPHIER_SSCOPE);
}
/** * __uniphier_cache_maint_common - run a queue operation for a particular level * * @data: cache controller specific data * @start: start address of range operation (don't care for "all" operation) * @size: data size of range operation (don't care for "all" operation) * @operation: flags to specify the desired cache operation
*/ staticvoid __uniphier_cache_maint_common(struct uniphier_cache_data *data, unsignedlong start, unsignedlong size,
u32 operation)
{ unsignedlong flags;
/* * No spin lock is necessary here because: * * [1] This outer cache controller is able to accept maintenance * operations from multiple CPUs at a time in an SMP system; if a * maintenance operation is under way and another operation is issued, * the new one is stored in the queue. The controller performs one * operation after another. If the queue is full, the status register, * UNIPHIER_SSCOPPQSEF, indicates that the queue registration has * failed. The status registers, UNIPHIER_{SSCOPPQSEF, SSCOLPQS}, have * different instances for each CPU, i.e. each CPU can track the status * of the maintenance operations triggered by itself. * * [2] The cache command registers, UNIPHIER_{SSCOQM, SSCOQAD, SSCOQSZ, * SSCOQWN}, are shared between multiple CPUs, but the hardware still * guarantees the registration sequence is atomic; the write access to * them are arbitrated by the hardware. The first accessor to the * register, UNIPHIER_SSCOQM, holds the access right and it is released * by reading the status register, UNIPHIER_SSCOPPQSEF. While one CPU * is holding the access right, other CPUs fail to register operations. * One CPU should not hold the access right for a long time, so local * IRQs should be disabled while the following sequence.
*/
local_irq_save(flags);
/* clear the complete notification flag */
writel_relaxed(UNIPHIER_SSCOLPQS_EF, data->op_base + UNIPHIER_SSCOLPQS);
do { /* set cache operation */
writel_relaxed(UNIPHIER_SSCOQM_CE | operation,
data->op_base + UNIPHIER_SSCOQM);
/* set address range if needed */ if (likely(UNIPHIER_SSCOQM_S_IS_RANGE(operation))) {
writel_relaxed(start, data->op_base + UNIPHIER_SSCOQAD);
writel_relaxed(size, data->op_base + UNIPHIER_SSCOQSZ);
}
} while (unlikely(readl_relaxed(data->op_base + UNIPHIER_SSCOPPQSEF) &
(UNIPHIER_SSCOPPQSEF_FE | UNIPHIER_SSCOPPQSEF_OE)));
/* wait until the operation is completed */ while (likely(readl_relaxed(data->op_base + UNIPHIER_SSCOLPQS) !=
UNIPHIER_SSCOLPQS_EF))
cpu_relax();
/* * If the start address is not aligned, * perform a cache operation for the first cache-line
*/
start = start & ~(data->line_size - 1);
size = end - start;
if (unlikely(size >= (unsignedlong)(-data->line_size))) { /* this means cache operation for all range */
__uniphier_cache_maint_all(data, operation); return;
}
/* * If the end address is not aligned, * perform a cache operation for the last cache-line
*/
size = ALIGN(size, data->line_size);
while (size) { unsignedlong chunk_size = min_t(unsignedlong, size,
data->range_op_max_size);
if (!of_match_node(uniphier_cache_match, np)) {
pr_err("L%d: not compatible with uniphier cache\n",
*cache_level); return -EINVAL;
}
if (of_property_read_u32(np, "cache-level", &level)) {
pr_err("L%d: cache-level is not specified\n", *cache_level); return -EINVAL;
}
if (level != *cache_level) {
pr_err("L%d: cache-level is unexpected value %d\n",
*cache_level, level); return -EINVAL;
}
if (!of_property_read_bool(np, "cache-unified")) {
pr_err("L%d: cache-unified is not specified\n", *cache_level); return -EINVAL;
}
data = kzalloc(sizeof(*data), GFP_KERNEL); if (!data) return -ENOMEM;
if (of_property_read_u32(np, "cache-line-size", &data->line_size) ||
!is_power_of_2(data->line_size)) {
pr_err("L%d: cache-line-size is unspecified or invalid\n",
*cache_level);
ret = -EINVAL; goto err;
}
if (of_property_read_u32(np, "cache-sets", &data->nsets) ||
!is_power_of_2(data->nsets)) {
pr_err("L%d: cache-sets is unspecified or invalid\n",
*cache_level);
ret = -EINVAL; goto err;
}
if (of_property_read_u32(np, "cache-size", &cache_size) ||
cache_size == 0 || cache_size % (data->nsets * data->line_size)) {
pr_err("L%d: cache-size is unspecified or invalid\n",
*cache_level);
ret = -EINVAL; goto err;
}
data->ctrl_base = of_iomap(np, 0); if (!data->ctrl_base) {
pr_err("L%d: failed to map control register\n", *cache_level);
ret = -ENOMEM; goto err;
}
data->rev_base = of_iomap(np, 1); if (!data->rev_base) {
pr_err("L%d: failed to map revision register\n", *cache_level);
ret = -ENOMEM; goto err;
}
data->op_base = of_iomap(np, 2); if (!data->op_base) {
pr_err("L%d: failed to map operation register\n", *cache_level);
ret = -ENOMEM; goto err;
}
data->way_ctrl_base = data->ctrl_base + 0xc00;
if (*cache_level == 2) {
u32 revision = readl(data->rev_base + UNIPHIER_SSCID); /* * The size of range operation is limited to (1 << 22) or less * for PH-sLD8 or older SoCs.
*/ if (revision <= 0x16)
data->range_op_max_size = (u32)1 << 22;
/* * Unfortunatly, the offset address of active way control base * varies from SoC to SoC.
*/ switch (revision) { case 0x11: /* sLD3 */
data->way_ctrl_base = data->ctrl_base + 0x870; break; case 0x12: /* LD4 */ case 0x16: /* sld8 */
data->way_ctrl_base = data->ctrl_base + 0x840; break; default: break;
}
}
data->range_op_max_size -= data->line_size;
INIT_LIST_HEAD(&data->list);
list_add_tail(&data->list, &uniphier_cache_list); /* no mutex */
/* * OK, this level has been successfully initialized. Look for the next * level cache. Do not roll back even if the initialization of the * next level cache fails because we want to continue with available * cache levels.
*/
next_np = of_find_next_cache_node(np); if (next_np) {
(*cache_level)++;
ret = __uniphier_cache_init(next_np, cache_level);
}
of_node_put(next_np);
int __init uniphier_cache_init(void)
{ struct device_node *np = NULL; unsignedint cache_level; int ret = 0;
/* look for level 2 cache */ while ((np = of_find_matching_node(np, uniphier_cache_match))) if (!of_property_read_u32(np, "cache-level", &cache_level) &&
cache_level == 2) break;
if (!np) return -ENODEV;
ret = __uniphier_cache_init(np, &cache_level);
of_node_put(np);
if (ret) { /* * Error out iif L2 initialization fails. Continue with any * error on L3 or outer because they are optional.
*/ if (cache_level == 2) {
pr_err("failed to initialize L2 cache\n"); return ret;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.