Skip to content

Commit 7005b7c

Browse files
Jason-JH LinAngeloGioacchino Del Regno
authored andcommitted
mailbox: mtk-cmdq: Add GCE hardware virtualization configuration
The GCE hardware virtualization configuration supports the isolation of GCE hardware resources across different OS environments. Each OS is treated as a virtual machine (VM) for GCE purposes. There are 6 VMs and 1 host VM. The host VM has main control over the GCE virtualization settings for all VMs. To properly access the GCE thread registers, it is necessary to configure access permissions for specific GCE threads assigned to different VMs. Currently, since only the host VM is being used, it is required to enable access permissions for all GCE threads for the host VM. There are 2 VM configurations: 1. VM_ID_MAP There are 4 registers to allocate 32 GCE threads across different VMs: VM_ID_MAP0 for threads 0-9, VM_ID_MAP1 for threads 10-19, VM_ID_MAP2 for threads 20-29, and VM_ID_MAP3 for threads 30-31. Each thread has a 3-bit configuration, where setting all bits to 1 configures the thread for the host VM. 2. VM_CPR_GSIZE It is used to allocate the CPR SRAM size to each VM. Each VM has 4-bit configuration, where setting bit 0-3 to configures the size of host VM. This setting must be configured before the VM configuration to prevent resource leakage. Signed-off-by: Jason-JH Lin <jason-jh.lin@mediatek.com> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Acked-by: Jassi Brar <jassisinghbrar@gmail.com> Acked-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
1 parent 266f357 commit 7005b7c

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

drivers/mailbox/mtk-cmdq-mailbox.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@
4343
#define GCE_CTRL_BY_SW GENMASK(2, 0)
4444
#define GCE_DDR_EN GENMASK(18, 16)
4545

46+
#define GCE_VM_ID_MAP(n) (0x5018 + (n) / 10 * 4)
47+
#define GCE_VM_ID_MAP_THR_FLD_SHIFT(n) ((n) % 10 * 3)
48+
#define GCE_VM_ID_MAP_HOST_VM GENMASK(2, 0)
49+
#define GCE_VM_CPR_GSIZE 0x50c4
50+
#define GCE_VM_CPR_GSIZE_FLD_SHIFT(vm_id) ((vm_id) * 4)
51+
#define GCE_VM_CPR_GSIZE_MAX GENMASK(3, 0)
52+
4653
#define CMDQ_THR_ACTIVE_SLOT_CYCLES 0x3200
4754
#define CMDQ_THR_ENABLED 0x1
4855
#define CMDQ_THR_DISABLED 0x0
@@ -89,6 +96,7 @@ struct gce_plat {
8996
u8 shift;
9097
bool control_by_sw;
9198
bool sw_ddr_en;
99+
bool gce_vm;
92100
u32 gce_num;
93101
};
94102

@@ -120,6 +128,45 @@ u8 cmdq_get_shift_pa(struct mbox_chan *chan)
120128
}
121129
EXPORT_SYMBOL(cmdq_get_shift_pa);
122130

131+
static void cmdq_vm_init(struct cmdq *cmdq)
132+
{
133+
int i;
134+
u32 vm_cpr_gsize = 0, vm_id_map = 0;
135+
u32 *vm_map = NULL;
136+
137+
if (!cmdq->pdata->gce_vm)
138+
return;
139+
140+
vm_map = kcalloc(cmdq->pdata->thread_nr, sizeof(*vm_map), GFP_KERNEL);
141+
if (!vm_map)
142+
return;
143+
144+
/* only configure the max CPR SRAM size to host vm (vm_id = 0) currently */
145+
vm_cpr_gsize = GCE_VM_CPR_GSIZE_MAX << GCE_VM_CPR_GSIZE_FLD_SHIFT(0);
146+
147+
/* set all thread mapping to host vm currently */
148+
for (i = 0; i < cmdq->pdata->thread_nr; i++)
149+
vm_map[i] = GCE_VM_ID_MAP_HOST_VM << GCE_VM_ID_MAP_THR_FLD_SHIFT(i);
150+
151+
/* set the amount of CPR SRAM to allocate to each VM */
152+
writel(vm_cpr_gsize, cmdq->base + GCE_VM_CPR_GSIZE);
153+
154+
/* config CPR_GSIZE before setting VM_ID_MAP to avoid data leakage */
155+
for (i = 0; i < cmdq->pdata->thread_nr; i++) {
156+
vm_id_map |= vm_map[i];
157+
/* config every 10 threads, e.g., thread id=0~9, 10~19, ..., into one register */
158+
if ((i + 1) % 10 == 0) {
159+
writel(vm_id_map, cmdq->base + GCE_VM_ID_MAP(i));
160+
vm_id_map = 0;
161+
}
162+
}
163+
/* config remaining threads settings */
164+
if (cmdq->pdata->thread_nr % 10 != 0)
165+
writel(vm_id_map, cmdq->base + GCE_VM_ID_MAP(cmdq->pdata->thread_nr - 1));
166+
167+
kfree(vm_map);
168+
}
169+
123170
static void cmdq_gctl_value_toggle(struct cmdq *cmdq, bool ddr_enable)
124171
{
125172
u32 val = cmdq->pdata->control_by_sw ? GCE_CTRL_BY_SW : 0;
@@ -164,6 +211,7 @@ static void cmdq_init(struct cmdq *cmdq)
164211

165212
WARN_ON(clk_bulk_enable(cmdq->pdata->gce_num, cmdq->clocks));
166213

214+
cmdq_vm_init(cmdq);
167215
cmdq_gctl_value_toggle(cmdq, true);
168216

169217
writel(CMDQ_THR_ACTIVE_SLOT_CYCLES, cmdq->base + CMDQ_THR_SLOT_CYCLES);

0 commit comments

Comments
 (0)