aboutsummaryrefslogtreecommitdiff
path: root/product/tc0/scp_romfw/config_ppu_v1.c
blob: 18d1f112a412171ce1a671716b5f478c4086153d (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
/*
 * Arm SCP/MCP Software
 * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include "config_power_domain.h"
#include "scp_css_mmap.h"
#include "tc0_core.h"

#include <mod_cmn_booker.h>
#include <mod_msys_rom.h>
#include <mod_power_domain.h>
#include <mod_ppu_v1.h>

#include <fwk_element.h>
#include <fwk_id.h>
#include <fwk_interrupt.h>
#include <fwk_macros.h>
#include <fwk_mm.h>
#include <fwk_module.h>
#include <fwk_module_idx.h>

#include <stdio.h>
#include <string.h>

/* Maximum PPU core name size including the null terminator */
#define PPU_CORE_NAME_SIZE 12

/* Maximum PPU cluster name size including the null terminator */
#define PPU_CLUS_NAME_SIZE 6

/* Lookup table for translating cluster indicies into CMN_BOOKER node IDs */
static const unsigned int cluster_idx_to_node_id[] = { 68 };

static struct fwk_element ppu_v1_system_element_table[] = {
    {
        .name = "SYS0",
        .data = &((struct mod_ppu_v1_pd_config){
            .pd_type = MOD_PD_TYPE_SYSTEM,
            .ppu.reg_base = SCP_PPU_SYS0_BASE,
            .observer_id = FWK_ID_NONE_INIT,
            .default_power_on = true,
        }),
    },
    {
        .name = "SYS1",
        .data = &((struct mod_ppu_v1_pd_config){
            .pd_type = MOD_PD_TYPE_SYSTEM,
            .ppu.reg_base = SCP_PPU_SYS1_BASE,
            .observer_id = FWK_ID_NONE_INIT,
            .default_power_on = true,
        }),
    },
    { 0 }, /* Termination entry */
};

static const struct fwk_element *tc0_ppu_v1_get_element_table(
    fwk_id_t module_id)
{
    struct fwk_element *element_table, *element;
    struct mod_ppu_v1_pd_config *pd_config_table, *pd_config;

    /*
     * Allocate element descriptors based on:
     *   Core0
     *   + Cluster0
     *   + Number of system power domain descriptors
     *   + 1 terminator descriptor
     */
    element_table = fwk_mm_calloc(
        2 + FWK_ARRAY_SIZE(ppu_v1_system_element_table) + 1,
        sizeof(struct fwk_element));
    if (element_table == NULL)
        return NULL;

    pd_config_table = fwk_mm_calloc(2, sizeof(struct mod_ppu_v1_pd_config));
    if (pd_config_table == NULL)
        return NULL;

    // pd_config for core0
    element = &element_table[0];
    pd_config = &pd_config_table[0];

    element->name = fwk_mm_alloc(PPU_CORE_NAME_SIZE, 1);
    if (element->name == NULL)
        return NULL;

    snprintf((char *)element->name, PPU_CORE_NAME_SIZE, "CLUS0CORE0");

    element->data = pd_config;

    pd_config->pd_type = MOD_PD_TYPE_CORE;
    pd_config->ppu.reg_base = SCP_PPU_CORE_BASE(0);
    pd_config->ppu.irq = FWK_INTERRUPT_NONE;
    pd_config->cluster_id = FWK_ID_ELEMENT(FWK_MODULE_IDX_PPU_V1, 1);
    pd_config->observer_id = FWK_ID_NONE;

    // pd_config for cluster0
    element = &element_table[1];
    pd_config = &pd_config_table[1];

    element->name = fwk_mm_alloc(PPU_CLUS_NAME_SIZE, 1);
    if (element->name == NULL)
        return NULL;

    snprintf((char *)element->name, PPU_CLUS_NAME_SIZE, "CLUS0");

    element->data = pd_config;

    pd_config->pd_type = MOD_PD_TYPE_CLUSTER;
    pd_config->ppu.reg_base = SCP_PPU_CLUSTER_BASE;
    pd_config->ppu.irq = FWK_INTERRUPT_NONE;

    pd_config->observer_id = fwk_module_id_cmn_booker;
    pd_config->observer_api = FWK_ID_API(
        FWK_MODULE_IDX_CMN_BOOKER, MOD_CMN_BOOKER_API_IDX_PPU_OBSERVER);
    pd_config->post_ppu_on_param = (void *)&cluster_idx_to_node_id[0];

    memcpy(
        &element_table[2],
        ppu_v1_system_element_table,
        sizeof(ppu_v1_system_element_table));

    return element_table;
}

/*
 * Power module configuration data
 */
struct fwk_module_config config_ppu_v1 = {
    .elements = FWK_MODULE_DYNAMIC_ELEMENTS(tc0_ppu_v1_get_element_table),
    .data =
        &(struct mod_ppu_v1_config){
            .pd_notification_id = FWK_ID_NOTIFICATION_INIT(
                FWK_MODULE_IDX_MSYS_ROM,
                MOD_MSYS_ROM_NOTIFICATION_IDX_POWER_SYSTOP),
            .pd_source_id = FWK_ID_MODULE_INIT(FWK_MODULE_IDX_MSYS_ROM),
        },
};