ATF:Gicv源码解读系列-gicv2_secure_ppi_sgi_setup_props

3、gicv2_secure_ppi_sgi_setup_props

配置安全G0 SGI和PPI的属性 。

/*******************************************************************************

  • Helper function to configure properties of secure G0 SGIs and PPIs.
    ******************************************************************************/
    void gicv2_secure_ppi_sgi_setup_props(uintptr_t gicd_base,
    const interrupt_prop_t *interrupt_props,
    unsigned int interrupt_props_num)
    {
    unsigned int i;
    uint32_t sec_ppi_sgi_mask = 0;
    const interrupt_prop_t *prop_desc;

    /* Make sure there’s a valid property array */
    if (interrupt_props_num != 0U)
    assert(interrupt_props != NULL);

1-禁止向CPU接口转发相应的中断。

/*
 * Disable all SGIs (imp. def.)/PPIs before configuring them. This is a
 * more scalable approach as it avoids clearing the enable bits in the
 * GICD_CTLR.
 */
gicd_write_icenabler(gicd_base, 0U, ~0U);

		禁止向CPU接口转发相应的中断。
		void gicd_write_icenabler(uintptr_t base, unsigned int id, unsigned int val)
		{
			unsigned int n = id >> ICENABLER_SHIFT;
		
			mmio_write_32(base + GICD_ICENABLER + (n << 2), val);
		}

2-将中断优先级初始化为默认值

访问器,用于写入与中断“id”对应的GIC分发器IPRIORITYR,一次4个中断id。
/
Setup the default PPI/SGI priorities doing four at a time */
for (i = 0U; i < MIN_SPI_ID; i += 4U)
gicd_write_ipriorityr(gicd_base, i, GICD_IPRIORITYR_DEF_VAL);

for (i = 0U; i < interrupt_props_num; i++) {
prop_desc = &interrupt_props[i];

if (prop_desc->intr_num >= MIN_SPI_ID)
continue;

3-将中断设置为安全中断

/* Configure this interrupt as a secure interrupt */
assert(prop_desc->intr_grp == GICV2_INTR_GROUP0);

4-设置该中断实际的触发方式

设置PPI的中断配置。忽略SGI的配置。
/*

  • Set interrupt configuration for PPIs. Configuration for SGIs
  • are ignored.
    */
    if ((prop_desc->intr_num >= MIN_PPI_ID) &&
    (prop_desc->intr_num < MIN_SPI_ID)) {
    gicd_set_icfgr(gicd_base, prop_desc->intr_num,
    prop_desc->intr_cfg);
    }

/* We have an SGI or a PPI. They are Group0 at reset */
sec_ppi_sgi_mask |= (1u << prop_desc->intr_num);

5-设置中断的优先级

/* Set the priority of this interrupt */
gicd_set_ipriorityr(gicd_base, prop_desc->intr_num,
prop_desc->intr_pri);
}

6-设置中断的分组属性

反转位掩码以创建非安全PPI和SGI的掩码。使用此位掩码对GICD_IGROUPR0进行编程。

/*

  • Invert the bitmask to create a mask for non-secure PPIs and SGIs.
  • Program the GICD_IGROUPR0 with this bit mask.
    */
    gicd_write_igroupr(gicd_base, 0, ~sec_ppi_sgi_mask);

7-使能中断

/* Enable the Group 0 SGIs and PPIs */
gicd_write_isenabler(gicd_base, 0, sec_ppi_sgi_mask);
}

到这里ATF中关于gic的主要的api就整完了,后续的api也可以通过这个去举一反三。

猜你喜欢

转载自blog.csdn.net/weixin_45264425/article/details/129434436
PPI