Commit 408c3768 authored by danh-arm's avatar danh-arm
Browse files

Merge pull request #48 from danh-arm/dh/major-refactoring

dh/major refactoring
parents b495bdef 97043ac9
......@@ -31,6 +31,8 @@
#ifndef __IO_SH_H__
#define __IO_SH_H__
struct io_dev_connector;
int register_io_dev_sh(struct io_dev_connector **dev_con);
#endif /* __IO_SH_H__ */
......@@ -31,7 +31,6 @@
#ifndef __ARCH_H__
#define __ARCH_H__
#include <bl_common.h>
/*******************************************************************************
* MIDR bit definitions
......@@ -330,16 +329,4 @@
#define EC_BITS(x) (x >> ESR_EC_SHIFT) & ESR_EC_MASK
#ifndef __ASSEMBLY__
/*******************************************************************************
* Function prototypes
******************************************************************************/
extern void early_exceptions(void);
extern void runtime_exceptions(void);
extern void bl1_arch_setup(void);
extern void bl2_arch_setup(void);
extern void bl31_arch_setup(void);
#endif /*__ASSEMBLY__*/
#endif /* __ARCH_H__ */
......@@ -31,10 +31,8 @@
#ifndef __ARCH_HELPERS_H__
#define __ARCH_HELPERS_H__
#include <arch.h>
#include <cdefs.h> /* For __dead2 */
#ifndef __ASSEMBLY__
#include <stdio.h>
/*******************************************************************************
* Aarch64 translation tables manipulation helper prototypes
......@@ -268,6 +266,5 @@ extern void write_cpuectlr(unsigned long);
extern void write_cptr_el2(unsigned long);
extern void write_cptr_el3(unsigned long);
#endif /*__ASSEMBLY__*/
#endif /* __ARCH_HELPERS_H__ */
......@@ -49,20 +49,20 @@ typedef enum {
MT_SECURE = 0 << 2,
MT_NS = 1 << 2
} mmap_attr;
} mmap_attr_t;
/*
* Structure for specifying a single region of memory.
*/
typedef struct {
typedef struct mmap_region {
unsigned long base;
unsigned long size;
mmap_attr attr;
} mmap_region;
mmap_attr_t attr;
} mmap_region_t;
extern void mmap_add_region(unsigned long base, unsigned long size,
unsigned attr);
extern void mmap_add(const mmap_region *mm);
extern void mmap_add(const mmap_region_t *mm);
extern void init_xlat_tables(void);
......
......@@ -35,19 +35,17 @@
#define BAKERY_LOCK_MAX_CPUS PLATFORM_CORE_COUNT
#ifndef __ASSEMBLY__
typedef struct {
typedef struct bakery_lock {
int owner;
volatile char entering[BAKERY_LOCK_MAX_CPUS];
volatile unsigned number[BAKERY_LOCK_MAX_CPUS];
} bakery_lock;
} bakery_lock_t;
#define NO_OWNER (-1)
void bakery_lock_init(bakery_lock* bakery);
void bakery_lock_get(unsigned long mpidr, bakery_lock* bakery);
void bakery_lock_release(unsigned long mpidr, bakery_lock* bakery);
int bakery_lock_try(unsigned long mpidr, bakery_lock* bakery);
#endif /*__ASSEMBLY__*/
void bakery_lock_init(bakery_lock_t *bakery);
void bakery_lock_get(unsigned long mpidr, bakery_lock_t *bakery);
void bakery_lock_release(unsigned long mpidr, bakery_lock_t *bakery);
int bakery_lock_try(unsigned long mpidr, bakery_lock_t *bakery);
#endif /* __BAKERY_LOCK_H__ */
/*
* Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
* Copyright (c) 2014, ARM Limited and Contributors. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
......@@ -28,39 +28,15 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __PM_H__
#define __PM_H__
#ifndef __ASSEMBLY__
/*******************************************************************************
* Structure populated by platform specific code to export routines which
* perform common low level pm functions
******************************************************************************/
typedef struct {
int (*cpu_on)(unsigned long);
int (*cpu_off)(unsigned long);
int (*cpu_suspend)(unsigned long);
int (*affinity_info)(unsigned long, unsigned int);
} pm_frontend_ops;
#ifndef __CASSERT_H__
#define __CASSERT_H__
/*******************************************************************************
* Structure populated by a generic power management api implementation e.g.
* psci to perform api specific bits after a cpu has been turned on.
* Macro to flag a compile time assertion. It uses the preprocessor to generate
* an invalid C construct if 'cond' evaluates to false.
* The following compilation error is triggered if the assertion fails:
* "error: size of array 'msg' is negative"
******************************************************************************/
typedef struct {
unsigned long (*cpu_off_finisher)(unsigned long);
unsigned long (*cpu_suspend_finisher)(unsigned long);
} pm_backend_ops;
/*******************************************************************************
* Function & variable prototypes
******************************************************************************/
extern pm_frontend_ops *get_pm_frontend_ops(void);
extern pm_backend_ops *get_pm_backend_ops(void);
extern void set_pm_frontend_ops(pm_frontend_ops *);
extern void set_pm_backend_ops(pm_backend_ops *);
#endif /*__ASSEMBLY__*/
#define CASSERT(cond, msg) typedef char msg[(cond) ? 1 : -1]
#endif /* __PM_H__ */
#endif /* __CASSERT_H__ */
......@@ -31,10 +31,7 @@
#ifndef __IO_H__
#define __IO_H__
#ifndef __ASSEMBLY__
#include <stdint.h>
#include <stdio.h> /* For ssize_t */
#include <stdio.h> /* For ssize_t */
/* Device type which can be used to enable policy decisions about which device
......@@ -45,7 +42,7 @@ typedef enum {
IO_TYPE_MEMMAP,
IO_TYPE_FIRMWARE_IMAGE_PACKAGE,
IO_TYPE_MAX
} io_type;
} io_type_t;
/* Modes used when seeking data on a supported device */
......@@ -55,7 +52,7 @@ typedef enum {
IO_SEEK_END,
IO_SEEK_CUR,
IO_SEEK_MAX
} io_seek_mode;
} io_seek_mode_t;
/* Connector type, providing a means of identifying a device to open */
......@@ -71,18 +68,18 @@ typedef struct io_entity *io_handle;
/* File specification - used to refer to data on a device supporting file-like
* entities */
typedef struct {
typedef struct io_file_spec {
const char *path;
unsigned int mode;
} io_file_spec;
} io_file_spec_t;
/* Block specification - used to refer to data on a device supporting
* block-like entities */
typedef struct {
typedef struct io_block_spec {
unsigned long offset;
size_t length;
} io_block_spec;
} io_block_spec_t;
/* Access modes used when accessing data on a device */
......@@ -116,7 +113,7 @@ int io_dev_close(io_dev_handle dev_handle);
/* Synchronous operations */
int io_open(io_dev_handle dev_handle, const void *spec, io_handle *handle);
int io_seek(io_handle handle, io_seek_mode mode, ssize_t offset);
int io_seek(io_handle handle, io_seek_mode_t mode, ssize_t offset);
int io_size(io_handle handle, size_t *length);
......@@ -128,5 +125,4 @@ int io_write(io_handle handle, const void *buffer, size_t length,
int io_close(io_handle handle);
#endif /* __ASSEMBLY__ */
#endif /* __IO_H__ */
......@@ -31,8 +31,6 @@
#ifndef __MMIO_H__
#define __MMIO_H__
#ifndef __ASSEMBLY__
#include <stdint.h>
extern void mmio_write_8(uintptr_t addr, uint8_t value);
......@@ -44,6 +42,4 @@ extern uint32_t mmio_read_32(uintptr_t addr);
extern void mmio_write_64(uintptr_t addr, uint64_t value);
extern uint64_t mmio_read_64(uintptr_t addr);
#endif /*__ASSEMBLY__*/
#endif /* __MMIO_H__ */
......@@ -31,6 +31,9 @@
#ifndef __SEMIHOSTING_H__
#define __SEMIHOSTING_H__
#include <stdio.h> /* For ssize_t */
#define SEMIHOSTING_SYS_OPEN 0x01
#define SEMIHOSTING_SYS_CLOSE 0x02
#define SEMIHOSTING_SYS_WRITE0 0x04
......
......@@ -31,7 +31,7 @@
#ifndef __SPINLOCK_H__
#define __SPINLOCK_H__
typedef struct {
typedef struct spinlock {
volatile unsigned int lock;
} spinlock_t;
......
......@@ -28,7 +28,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <arch_helpers.h>
#include <arch.h>
#include <asm_macros.S>
.globl dcisw
......
......@@ -28,8 +28,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <arch_helpers.h>
#include <runtime_svc.h>
#include <arch.h>
#include <asm_macros.S>
.globl enable_irq
......
......@@ -28,7 +28,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <arch_helpers.h>
#include <arch.h>
#include <asm_macros.S>
.globl read_vbar_el1
......
......@@ -28,7 +28,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <arch_helpers.h>
#include <asm_macros.S>
.globl tlbialle1
......
......@@ -28,9 +28,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <string.h>
#include <assert.h>
#include <arch.h>
#include <assert.h>
/*******************************************************************************
* Helper to create a level 1/2 table descriptor which points to a level 2/3
......
......@@ -61,14 +61,14 @@ static unsigned next_xlat;
* Array of all memory regions stored in order of ascending base address.
* The list is terminated by the first entry with size == 0.
*/
static mmap_region mmap[MAX_MMAP_REGIONS + 1];
static mmap_region_t mmap[MAX_MMAP_REGIONS + 1];
static void print_mmap(void)
{
#if DEBUG_XLAT_TABLE
debug_print("mmap:\n");
mmap_region *mm = mmap;
mmap_region_t *mm = mmap;
while (mm->size) {
debug_print(" %010lx %10lx %x\n", mm->base, mm->size, mm->attr);
++mm;
......@@ -79,8 +79,8 @@ static void print_mmap(void)
void mmap_add_region(unsigned long base, unsigned long size, unsigned attr)
{
mmap_region *mm = mmap;
mmap_region *mm_last = mm + sizeof(mmap) / sizeof(mmap[0]) - 1;
mmap_region_t *mm = mmap;
mmap_region_t *mm_last = mm + sizeof(mmap) / sizeof(mmap[0]) - 1;
assert(IS_PAGE_ALIGNED(base));
assert(IS_PAGE_ALIGNED(size));
......@@ -103,7 +103,7 @@ void mmap_add_region(unsigned long base, unsigned long size, unsigned attr)
mm->attr = attr;
}
void mmap_add(const mmap_region *mm)
void mmap_add(const mmap_region_t *mm)
{
while (mm->size) {
mmap_add_region(mm->base, mm->size, mm->attr);
......@@ -140,7 +140,7 @@ static unsigned long mmap_desc(unsigned attr, unsigned long addr,
return desc;
}
static int mmap_region_attr(mmap_region *mm, unsigned long base,
static int mmap_region_attr(mmap_region_t *mm, unsigned long base,
unsigned long size)
{
int attr = mm->attr;
......@@ -167,7 +167,7 @@ static int mmap_region_attr(mmap_region *mm, unsigned long base,
}
}
static mmap_region *init_xlation_table(mmap_region *mm, unsigned long base,
static mmap_region_t *init_xlation_table(mmap_region_t *mm, unsigned long base,
unsigned long *table, unsigned level)
{
unsigned level_size_shift = L1_XLAT_ADDRESS_SHIFT - (level - 1) *
......
......@@ -28,11 +28,10 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <stddef.h>
#include <assert.h>
#include "io_storage.h"
#include "io_driver.h"
#include <io_driver.h>
#include <io_storage.h>
#include <stddef.h>
#define MAX_DEVICES(plat_data) \
......@@ -40,24 +39,24 @@
/* Storage for a fixed maximum number of IO entities, definable by platform */
static struct io_entity entity_pool[MAX_IO_HANDLES];
static io_entity_t entity_pool[MAX_IO_HANDLES];
/* Simple way of tracking used storage - each entry is NULL or a pointer to an
* entity */
static struct io_entity *entity_map[MAX_IO_HANDLES];
static io_entity_t *entity_map[MAX_IO_HANDLES];
/* Track number of allocated entities */
static unsigned int entity_count;
/* Used to keep a reference to platform-specific data */
static struct io_plat_data *platform_data;
static io_plat_data_t *platform_data;
#if DEBUG /* Extra validation functions only used in debug builds */
/* Return a boolean value indicating whether a device connector is valid */
static int is_valid_dev_connector(const struct io_dev_connector *dev_con)
static int is_valid_dev_connector(const io_dev_connector_t *dev_con)
{
int result = (dev_con != NULL) && (dev_con->dev_open != NULL);
return result;
......@@ -67,7 +66,7 @@ static int is_valid_dev_connector(const struct io_dev_connector *dev_con)
/* Return a boolean value indicating whether a device handle is valid */
static int is_valid_dev(io_dev_handle handle)
{
const struct io_dev_info *dev = handle;
const io_dev_info_t *dev = handle;
int result = (dev != NULL) && (dev->funcs != NULL) &&
(dev->funcs->type != NULL) &&
(dev->funcs->type() < IO_TYPE_MAX);
......@@ -78,14 +77,14 @@ static int is_valid_dev(io_dev_handle handle)
/* Return a boolean value indicating whether an IO entity is valid */
static int is_valid_entity(io_handle handle)
{
const struct io_entity *entity = handle;
const io_entity_t *entity = handle;
int result = (entity != NULL) && (is_valid_dev(entity->dev_handle));
return result;
}
/* Return a boolean value indicating whether a seek mode is valid */
static int is_valid_seek_mode(io_seek_mode mode)
static int is_valid_seek_mode(io_seek_mode_t mode)
{
return ((mode != IO_SEEK_INVALID) && (mode < IO_SEEK_MAX));
}
......@@ -94,8 +93,8 @@ static int is_valid_seek_mode(io_seek_mode mode)
/* Open a connection to a specific device */
static int dev_open(const struct io_dev_connector *dev_con, void *dev_spec,
struct io_dev_info **dev_info)
static int dev_open(const io_dev_connector_t *dev_con, void *dev_spec,
io_dev_info_t **dev_info)
{
int result = IO_FAIL;
assert(dev_info != NULL);
......@@ -107,7 +106,7 @@ static int dev_open(const struct io_dev_connector *dev_con, void *dev_spec,
/* Set a handle to track an entity */
static void set_handle(io_handle *handle, struct io_entity *entity)
static void set_handle(io_handle *handle, io_entity_t *entity)
{
assert(handle != NULL);
*handle = entity;
......@@ -217,7 +216,7 @@ int io_dev_init(struct io_dev_info *dev_handle, const void *init_params)
assert(dev_handle != NULL);
assert(is_valid_dev(dev_handle));
struct io_dev_info *dev = dev_handle;
io_dev_info_t *dev = dev_handle;
if (dev->funcs->dev_init != NULL) {
result = dev->funcs->dev_init(dev, init_params);
......@@ -238,7 +237,7 @@ int io_dev_close(io_dev_handle dev_handle)
assert(dev_handle != NULL);
assert(is_valid_dev(dev_handle));
struct io_dev_info *dev = dev_handle;
io_dev_info_t *dev = dev_handle;
if (dev->funcs->dev_close != NULL) {
result = dev->funcs->dev_close(dev);
......@@ -261,8 +260,8 @@ int io_open(io_dev_handle dev_handle, const void *spec, io_handle *handle)
assert((spec != NULL) && (handle != NULL));
assert(is_valid_dev(dev_handle));
struct io_dev_info *dev = dev_handle;
struct io_entity *entity;
io_dev_info_t *dev = dev_handle;
io_entity_t *entity;
result = allocate_entity(&entity);
......@@ -281,14 +280,14 @@ int io_open(io_dev_handle dev_handle, const void *spec, io_handle *handle)
/* Seek to a specific position in an IO entity */
int io_seek(io_handle handle, io_seek_mode mode, ssize_t offset)
int io_seek(io_handle handle, io_seek_mode_t mode, ssize_t offset)
{
int result = IO_FAIL;
assert(is_valid_entity(handle) && is_valid_seek_mode(mode));
struct io_entity *entity = handle;
io_entity_t *entity = handle;
struct io_dev_info *dev = entity->dev_handle;
io_dev_info_t *dev = entity->dev_handle;
if (dev->funcs->seek != NULL)
result = dev->funcs->seek(entity, mode, offset);
......@@ -305,9 +304,9 @@ int io_size(io_handle handle, size_t *length)
int result = IO_FAIL;
assert(is_valid_entity(handle) && (length != NULL));
struct io_entity *entity = handle;
io_entity_t *entity = handle;
struct io_dev_info *dev = entity->dev_handle;
io_dev_info_t *dev = entity->dev_handle;
if (dev->funcs->size != NULL)
result = dev->funcs->size(entity, length);
......@@ -324,9 +323,9 @@ int io_read(io_handle handle, void *buffer, size_t length, size_t *length_read)
int result = IO_FAIL;
assert(is_valid_entity(handle) && (buffer != NULL));
struct io_entity *entity = handle;
io_entity_t *entity = handle;
struct io_dev_info *dev = entity->dev_handle;
io_dev_info_t *dev = entity->dev_handle;
if (dev->funcs->read != NULL)
result = dev->funcs->read(entity, buffer, length, length_read);
......@@ -344,9 +343,9 @@ int io_write(io_handle handle, const void *buffer, size_t length,
int result = IO_FAIL;
assert(is_valid_entity(handle) && (buffer != NULL));
struct io_entity *entity = handle;
io_entity_t *entity = handle;
struct io_dev_info *dev = entity->dev_handle;
io_dev_info_t *dev = entity->dev_handle;
if (dev->funcs->write != NULL) {
result = dev->funcs->write(entity, buffer, length,
......@@ -364,9 +363,9 @@ int io_close(io_handle handle)
int result = IO_FAIL;
assert(is_valid_entity(handle));
struct io_entity *entity = handle;
io_entity_t *entity = handle;
struct io_dev_info *dev = entity->dev_handle;
io_dev_info_t *dev = entity->dev_handle;
if (dev->funcs->close != NULL)
result = dev->funcs->close(entity);
......
......@@ -28,11 +28,10 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <arch_helpers.h>
#include <assert.h>
#include <string.h>
#include <bakery_lock.h>
#include <arch_helpers.h>
#include <string.h>
/*
* Functions in this file implement Bakery Algorithm for mutual exclusion.
......@@ -59,14 +58,14 @@
#define assert_bakery_entry_valid(entry, bakery) do { \
assert(bakery); \
assert(entry < BAKERY_LOCK_MAX_CPUS); \
} while(0)
} while (0)
/* Convert a ticket to priority */
#define PRIORITY(t, pos) (((t) << 8) | (pos))
/* Initialize Bakery Lock to reset ownership and all ticket values */
void bakery_lock_init(bakery_lock * bakery)
void bakery_lock_init(bakery_lock_t *bakery)
{
assert(bakery);
......@@ -77,7 +76,7 @@ void bakery_lock_init(bakery_lock * bakery)
/* Obtain a ticket for a given CPU */
static unsigned int bakery_get_ticket(bakery_lock *bakery, unsigned int me)
static unsigned int bakery_get_ticket(bakery_lock_t *bakery, unsigned int me)
{
unsigned int my_ticket, their_ticket;
unsigned int they;
......@@ -124,7 +123,7 @@ static unsigned int bakery_get_ticket(bakery_lock *bakery, unsigned int me)
* of others'. The CPU with the highest priority (lowest numerical value)
* acquires the lock
*/
void bakery_lock_get(unsigned long mpidr, bakery_lock *bakery)
void bakery_lock_get(unsigned long mpidr, bakery_lock_t *bakery)
{
unsigned int they, me;
unsigned int my_ticket, my_prio, their_ticket;
......@@ -176,7 +175,7 @@ void bakery_lock_get(unsigned long mpidr, bakery_lock *bakery)
/* Release the lock and signal contenders */
void bakery_lock_release(unsigned long mpidr, bakery_lock * bakery)
void bakery_lock_release(unsigned long mpidr, bakery_lock_t *bakery)
{
unsigned int me = platform_get_core_pos(mpidr);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment