index cd36edd993dfa26c62215d0529b64656bd40c65e..daf445263a0dd48e892ee24fb670f0082f7cccdf 100755 (executable)
--- a/lib/system/generic/env.c
+++ b/lib/system/generic/env.c
**************************************************************************/
#include "openamp/env.h"
-#include "machine.h"
-#include "machine_system.h"
-
#include <stdlib.h>
#include <string.h>
-static void acquire_spin_lock(void *plock);
-static void release_spin_lock(void *plock);
-
-/* Max supprted ISR counts */
-#define ISR_COUNT 4
-/**
- * Structure to keep track of registered ISR's.
- */
-struct isr_info {
- int vector;
- int priority;
- int type;
- char *name;
- int shared;
- void *data;
- void (*isr)(int vector, void *data);
-};
-struct isr_info isr_table[ISR_COUNT];
-static int intr_count = 0;
-/* Flag to show status of global interrupts. 0 for disabled and 1 for enabled. This
- * is added to prevent recursive global interrupts enablement/disablement.
- */
-static int intr_enable_flag = 1;
-
-/**
- * env_allocate_memory - implementation
- *
- * @param size
- */
-void *env_allocate_memory(unsigned int size)
-{
- return (malloc(size));
-}
-
-/**
- * env_free_memory - implementation
- *
- * @param ptr
- */
-void env_free_memory(void *ptr)
-{
- if (ptr != NULL) {
- free(ptr);
- }
-}
-
-/**
- * env_map_vatopa - implementation
- *
- * @param address
- */
-unsigned long env_map_vatopa(void *address)
-{
- return platform_vatopa(address);
-}
-
-/**
- * env_map_patova - implementation
- *
- * @param address
- */
-void *env_map_patova(unsigned long address)
-{
- return platform_patova(address);
-}
-
-/**
- * env_create_sync_lock
- *
- * Creates a synchronization lock primitive. It is used
- * when signal has to be sent from the interrupt context to main
- * thread context.
- */
-int env_create_sync_lock(void **lock, int state)
-{
- int *slock;
-
- slock = (int *)malloc(sizeof(int));
- if (slock) {
- *slock = state;
- *lock = slock;
- } else {
- *lock = NULL;
- return -1;
- }
-
- return 0;
-}
-
-/**
- * env_delete_sync_lock
- *
- * Deletes the given lock
- *
- */
-void env_delete_sync_lock(void *lock)
-{
- if (lock)
- free(lock);
-}
-
-/**
- * env_acquire_sync_lock
- *
- * Tries to acquire the lock, if lock is not available then call to
- * this function waits for lock to become available.
- */
-void env_acquire_sync_lock(void *lock)
-{
- acquire_spin_lock(lock);
-}
-
-/**
- * env_release_sync_lock
- *
- * Releases the given lock.
- */
-
-void env_release_sync_lock(void *lock)
-{
- release_spin_lock(lock);
-}
-
/**
* env_sleep_msec
*
}
-/**
- * env_disable_interrupts
- *
- * Disables system interrupts
- *
- */
-void env_disable_interrupts()
-{
- if (intr_enable_flag == 1) {
- disable_global_interrupts();
- intr_enable_flag = 0;
- }
-}
-
-/**
- * env_restore_interrupts
- *
- * Enables system interrupts
- *
- */
-void env_restore_interrupts()
-{
- if (intr_enable_flag == 0) {
- restore_global_interrupts();
- intr_enable_flag = 1;
- }
-}
-
-/**
- * env_register_isr_shared
- *
- * Registers interrupt handler for the given interrupt vector.
- *
- * @param vector - interrupt vector number
- * @param isr - interrupt handler
- * @param name - interrupt name
- * @param shared - if the interrupt is shared or not
- */
-void env_register_isr_shared(int vector, void *data,
- void (*isr) (int vector, void *data),
- char *name,
- int shared)
-{
- env_disable_interrupts();
-
- if (intr_count < ISR_COUNT) {
- /* Save interrupt data */
- isr_table[intr_count].vector = vector;
- isr_table[intr_count].data = data;
- isr_table[intr_count].name = name;
- isr_table[intr_count].shared = shared;
- isr_table[intr_count++].isr = isr;
- }
-
- env_restore_interrupts();
-}
-/**
- * env_register_isr
- *
- * Registers interrupt handler for the given interrupt vector.
- *
- * @param vector - interrupt vector number
- * @param isr - interrupt handler
- */
-void env_register_isr(int vector, void *data,
- void (*isr) (int vector, void *data))
-{
- env_register_isr_shared(vector, data, isr, 0, 0);
-}
-
-void env_update_isr(int vector, void *data,
- void (*isr) (int vector, void *data),
- char *name,
- int shared)
-{
- int idx;
- struct isr_info *info;
-
- env_disable_interrupts();
-
- for (idx = 0; idx < ISR_COUNT; idx++) {
- info = &isr_table[idx];
- if (info->vector == vector) {
- if (name && strcmp(info->name, name)) {
- continue;
- }
- info->data = data;
- info->isr = isr;
- info->shared = shared;
- break;
- }
- }
-
- env_restore_interrupts();
-}
-
-/**
- * env_enable_interrupt
- *
- * Enables the given interrupt
- *
- * @param vector - interrupt vector number
- * @param priority - interrupt priority
- * @param polarity - interrupt polarity
- */
-
-void env_enable_interrupt(unsigned int vector, unsigned int priority,
- unsigned int polarity)
-{
- int idx;
-
- env_disable_interrupts();
-
- for (idx = 0; idx < ISR_COUNT; idx++) {
- if (isr_table[idx].vector == (int)vector) {
- isr_table[idx].priority = priority;
- isr_table[idx].type = polarity;
- platform_interrupt_enable(vector, polarity, priority);
- break;
- }
- }
-
- env_restore_interrupts();
-}
-
-/**
- * env_disable_interrupt
- *
- * Disables the given interrupt
- *
- * @param vector - interrupt vector number
- */
-
-void env_disable_interrupt(unsigned int vector)
-{
- platform_interrupt_disable(vector);
-}
-
-/**
- * env_map_memory
- *
- * Enables memory mapping for given memory region.
- *
- * @param pa - physical address of memory
- * @param va - logical address of memory
- * @param size - memory size
- * param flags - flags for cache/uncached and access type
- */
-
-void env_map_memory(unsigned int pa, unsigned int va, unsigned int size,
- unsigned int flags)
-{
- platform_map_mem_region(va, pa, size, flags);
-}
-
-/**
- * env_disable_cache
- *
- * Disables system caches.
- *
- */
-
-void env_disable_cache(void)
-{
- platform_cache_all_flush_invalidate();
- platform_cache_disable();
-}
-
-/**
- * env_flush_invalidate_all_caches
- *
- * Flush and Invalidate all caches.
- *
- */
-
-void env_flush_invalidate_all_caches(void)
-{
- platform_cache_all_flush_invalidate();
-}
-
-
/**
*
* env_get_timestamp
return 0;
}
-/*========================================================= */
-/* Util data / functions for BM */
-
-void bm_env_isr(int vector)
-{
- int idx;
- struct isr_info *info;
-
- env_disable_interrupt(vector);
- for (idx = 0; idx < ISR_COUNT; idx++) {
- info = &isr_table[idx];
- if (info->vector == vector) {
- info->isr(info->vector, info->data);
- env_enable_interrupt(info->vector, info->priority,
- info->type);
- if (!info->shared)
- break;
- }
- }
-}
-
-/**
- *
- * acquire_spin_lock
- *
- */
-static void acquire_spin_lock(void *plock)
-{
- const unsigned int lockVal = 0;
- volatile unsigned int retVal;
-
- do {
- retVal = xchg(plock, lockVal);
- } while (retVal == lockVal);
-}
-
-/**
- * release_spin_lock
- */
-static void release_spin_lock(void *plock)
-{
- MEM_BARRIER();
-
- xchg(plock, 1);
-}