Browse Source

Add macro to calculate number of elements in an array

This patch defines the ARRAY_SIZE macro for calculating number of elements
in an array and uses it where appropriate.

Change-Id: I72746a9229f0b259323972b498b9a3999731bc9b
pull/269/head
Vikram Kanigiri 10 years ago
parent
commit
a7e98ad514
  1. 2
      drivers/io/io_fip.c
  2. 2
      include/common/bl_common.h
  3. 3
      lib/aarch64/xlat_tables.c
  4. 7
      plat/fvp/aarch64/fvp_common.c
  5. 11
      plat/juno/aarch64/juno_common.c

2
drivers/io/io_fip.c

@ -143,7 +143,7 @@ static int file_to_uuid(const char *filename, uuid_t *uuid)
int i;
int status = -EINVAL;
for (i = 0; i < (sizeof(name_uuid) / sizeof(name_uuid[0])); i++) {
for (i = 0; i < ARRAY_SIZE(name_uuid); i++) {
if (strcmp(filename, name_uuid[i].name) == 0) {
copy_uuid(uuid, &name_uuid[i].uuid);
status = 0;

2
include/common/bl_common.h

@ -108,6 +108,8 @@
#include <stdint.h>
#include <stddef.h>
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
/*******************************************************************************
* Structure used for telling the next BL how much of a particular type of
* memory is available for its use and how much is already used.

3
lib/aarch64/xlat_tables.c

@ -31,6 +31,7 @@
#include <arch.h>
#include <arch_helpers.h>
#include <assert.h>
#include <bl_common.h>
#include <cassert.h>
#include <platform_def.h>
#include <string.h>
@ -89,7 +90,7 @@ void mmap_add_region(unsigned long base_pa, unsigned long base_va,
unsigned long size, unsigned attr)
{
mmap_region_t *mm = mmap;
mmap_region_t *mm_last = mm + sizeof(mmap) / sizeof(mmap[0]) - 1;
mmap_region_t *mm_last = mm + ARRAY_SIZE(mmap) - 1;
unsigned long pa_end = base_pa + size - 1;
unsigned long va_end = base_va + size - 1;

7
plat/fvp/aarch64/fvp_common.c

@ -115,7 +115,7 @@ const mmap_region_t fvp_mmap[] = {
};
#endif
CASSERT((sizeof(fvp_mmap)/sizeof(fvp_mmap[0])) + FVP_BL_REGIONS \
CASSERT(ARRAY_SIZE(fvp_mmap) + FVP_BL_REGIONS \
<= MAX_MMAP_REGIONS, assert_max_mmap_regions);
/* Array of secure interrupts to be configured by the gic driver */
@ -132,9 +132,6 @@ const unsigned int irq_sec_array[] = {
IRQ_SEC_SGI_7
};
const unsigned int num_sec_irqs = sizeof(irq_sec_array) /
sizeof(irq_sec_array[0]);
/*******************************************************************************
* Macro generating the code for the function setting up the pagetables as per
* the platform memory map & initialize the mmu, for the given exception level
@ -326,7 +323,7 @@ void fvp_gic_init(void)
plat_config.gicd_base,
BASE_GICR_BASE,
irq_sec_array,
num_sec_irqs);
ARRAY_SIZE(irq_sec_array));
}

11
plat/juno/aarch64/juno_common.c

@ -114,7 +114,7 @@ static const mmap_region_t juno_mmap[] = {
};
#endif
CASSERT((sizeof(juno_mmap)/sizeof(juno_mmap[0])) + JUNO_BL_REGIONS \
CASSERT(ARRAY_SIZE(juno_mmap) + JUNO_BL_REGIONS \
<= MAX_MMAP_REGIONS, assert_max_mmap_regions);
/* Array of secure interrupts to be configured by the gic driver */
@ -136,9 +136,6 @@ const unsigned int irq_sec_array[] = {
IRQ_SEC_SGI_7
};
const unsigned int num_sec_irqs = sizeof(irq_sec_array) /
sizeof(irq_sec_array[0]);
/*******************************************************************************
* Macro generating the code for the function setting up the pagetables as per
* the platform memory map & initialize the mmu, for the given exception level
@ -211,5 +208,9 @@ uint64_t plat_get_syscnt_freq(void)
void plat_gic_init(void)
{
arm_gic_init(GICC_BASE, GICD_BASE, 0, irq_sec_array, num_sec_irqs);
arm_gic_init(GICC_BASE,
GICD_BASE,
0,
irq_sec_array,
ARRAY_SIZE(irq_sec_array));
}

Loading…
Cancel
Save