static void kvm_arm_gic_get(GICState *s)

{

    uint32_t reg;

    int i;

    int cpu;



    if (!kvm_arm_gic_can_save_restore(s)) {

            DPRINTF("Cannot get kernel gic state, no kernel interface");

            return;

    }



    







    

    kvm_gicd_access(s, 0x0, 0, &reg, false);

    s->enabled = reg & 1;



    

    kvm_gicd_access(s, 0x4, 0, &reg, false);

    s->num_irq = ((reg & 0x1f) + 1) * 32;

    s->num_cpu = ((reg & 0xe0) >> 5) + 1;



    if (s->num_irq > GIC_MAXIRQ) {

            fprintf(stderr, "Too many IRQs reported from the kernel: %d\n",

                    s->num_irq);

            abort();

    }



    

    kvm_gicd_access(s, 0x8, 0, &reg, false);



    

    for_each_irq_reg(i, s->num_irq, 1) {

        kvm_gicd_access(s, 0x80 + (i * 4), 0, &reg, false);

        if (reg != 0) {

            fprintf(stderr, "Unsupported GICD_IGROUPRn value: %08x\n",

                    reg);

            abort();

        }

    }



    

    for (i = 0; i < s->num_irq; i++) {

        memset(&s->irq_state[i], 0, sizeof(s->irq_state[0]));

    }



    

    kvm_dist_get(s, 0x100, 1, s->num_irq, translate_enabled);



    

    kvm_dist_get(s, 0x200, 1, s->num_irq, translate_pending);



    

    kvm_dist_get(s, 0x300, 1, s->num_irq, translate_active);



    

    kvm_dist_get(s, 0xc00, 2, s->num_irq, translate_trigger);



    

    kvm_dist_get(s, 0x400, 8, s->num_irq, translate_priority);



    

    kvm_dist_get(s, 0x800, 8, s->num_irq, translate_targets);



    

    kvm_dist_get(s, 0xf10, 8, GIC_NR_SGIS, translate_sgisource);





    







    for (cpu = 0; cpu < s->num_cpu; cpu++) {

        

        kvm_gicc_access(s, 0x00, cpu, &reg, false);

        s->cpu_enabled[cpu] = (reg & 1);



        

        kvm_gicc_access(s, 0x04, cpu, &reg, false);

        s->priority_mask[cpu] = (reg & 0xff);



        

        kvm_gicc_access(s, 0x08, cpu, &reg, false);

        s->bpr[cpu] = (reg & 0x7);



        

        kvm_gicc_access(s, 0x1c, cpu, &reg, false);

        s->abpr[cpu] = (reg & 0x7);



        

        for (i = 0; i < 4; i++) {

            kvm_gicc_access(s, 0xd0 + i * 4, cpu, &reg, false);

            s->apr[i][cpu] = reg;

        }

    }

}
