POK(kernelpart)
/home/jaouen/pok_official/pok/trunk/kernel/arch/ppc/space.c File Reference
#include <types.h>
#include <errno.h>
#include <libc.h>
#include <bsp.h>
#include <core/sched.h>
#include <arch.h>
#include "thread.h"
#include "msr.h"

Go to the source code of this file.

Data Structures

struct  pok_space
struct  ppc_pte_t

Defines

#define KERNEL_STACK_SIZE   8192
#define PPC_SR_KP   (1 << 29)
#define PPC_SR_Ks   (1 << 30)
#define PPC_SR_T   (1 << 31)
#define PPC_PTE_V   (1 << 31)
#define POK_PAGE_SIZE   (1 << 12)
#define POK_PAGE_MASK   (~(POK_PAGE_SIZE - 1))
#define PPC_PTE_H   (1 << 6)
#define PPC_PTE_R   (1 << 8)
#define PPC_PTE_C   (1 << 7)
#define PPC_PTE_W   (1 << 6)
#define PPC_PTE_I   (1 << 5)
#define PPC_PTE_M   (1 << 4)
#define PPC_PTE_G   (1 << 3)
#define PPC_PTE_PP_NO   0
#define PPC_PTE_PP_RO   1
#define PPC_PTE_PP_RW   2

Functions

pok_ret_t pok_create_space (uint8_t partition_id, uint32_t addr, uint32_t size)
pok_ret_t pok_space_switch (uint8_t old_partition_id, uint8_t new_partition_id)
uint32_t pok_space_base_vaddr (uint32_t addr)
void pok_arch_rfi (void)
uint32_t pok_space_context_create (uint8_t partition_id, uint32_t entry_rel, uint32_t stack_rel, uint32_t arg1, uint32_t arg2)
void pok_arch_space_init (void)
void pok_arch_isi_int (uint32_t pc, uint32_t msr)
void pok_arch_dsi_int (uint32_t dar, uint32_t dsisr)

Variables

struct pok_space spaces [POK_CONFIG_NB_PARTITIONS]

Define Documentation

#define KERNEL_STACK_SIZE   8192

Definition at line 28 of file space.c.

#define POK_PAGE_MASK   (~(POK_PAGE_SIZE - 1))

Definition at line 120 of file space.c.

#define POK_PAGE_SIZE   (1 << 12)

Definition at line 119 of file space.c.

#define PPC_PTE_C   (1 << 7)

Definition at line 123 of file space.c.

#define PPC_PTE_G   (1 << 3)

Definition at line 127 of file space.c.

#define PPC_PTE_H   (1 << 6)

Definition at line 121 of file space.c.

#define PPC_PTE_I   (1 << 5)

Definition at line 125 of file space.c.

#define PPC_PTE_M   (1 << 4)

Definition at line 126 of file space.c.

#define PPC_PTE_PP_NO   0

Definition at line 128 of file space.c.

#define PPC_PTE_PP_RO   1

Definition at line 129 of file space.c.

#define PPC_PTE_PP_RW   2

Definition at line 130 of file space.c.

#define PPC_PTE_R   (1 << 8)

Definition at line 122 of file space.c.

#define PPC_PTE_V   (1 << 31)

Definition at line 118 of file space.c.

#define PPC_PTE_W   (1 << 6)

Definition at line 124 of file space.c.

#define PPC_SR_KP   (1 << 29)

Definition at line 30 of file space.c.

#define PPC_SR_Ks   (1 << 30)

Definition at line 31 of file space.c.

#define PPC_SR_T   (1 << 31)

Definition at line 32 of file space.c.


Function Documentation

void pok_arch_dsi_int ( uint32_t  dar,
uint32_t  dsisr 
)

Definition at line 203 of file space.c.

{
#ifdef POK_NEEDS_DEBUG
  printf("dsi_int: part=%d, dar=%x dsisr=%x\n",
         pok_current_partition, dar, dsisr);
#endif

  if (dsisr & (1 << 30))
    {
      /* Page fault  */
      if (dar < spaces[pok_current_partition].size)
        {
          uint32_t vaddr = dar & POK_PAGE_MASK;
          uint32_t v;
          v = (spaces[pok_current_partition].phys_base + vaddr) & POK_PAGE_MASK;
          v |= PPC_PTE_R | PPC_PTE_C | PPC_PTE_PP_RW;
          pok_insert_pte (pok_current_partition, vaddr, v);
          return;
        }
    }
#ifdef POK_NEEDS_DEBUG
   printf("[DEBUG] Infinite loop in pok_arch_dsi_int\n");
#endif
  while (1)
    ;
}
void pok_arch_isi_int ( uint32_t  pc,
uint32_t  msr 
)

Definition at line 168 of file space.c.

{

#ifdef POK_NEEDS_DEBUG
  printf("isi_int: part=%d, pc=%x msr=%x\n",
         pok_current_partition, pc, msr);

  if (msr & ((1 << 28) | (1 << 27)))
  {
    printf (" Bad access\n");
  }
#endif

  if (msr & (1 << 30))
    {
      /* Page fault  */
      if (pc < spaces[pok_current_partition].size)
        {
          uint32_t vaddr = pc & POK_PAGE_MASK;
          uint32_t v;
          v = (spaces[pok_current_partition].phys_base + vaddr) & POK_PAGE_MASK;
          v |= PPC_PTE_R | PPC_PTE_C | PPC_PTE_PP_RW;
          pok_insert_pte (pok_current_partition, vaddr, v);
          return;
        }
    }

#ifdef POK_NEEDS_DEBUG
   printf("[DEBUG] Infinite loop in pok_arch_isi_int\n");
#endif

  while (1)
    ;
}
void pok_arch_rfi ( void  )
void pok_arch_space_init ( void  )

Definition at line 132 of file space.c.

{
  uint32_t sdr1;

  pt_base = 0;
  pt_mask = 0x3ff;

  sdr1 = pt_base | (pt_mask >> 10);
  asm volatile ("mtsdr1 %0" : : "r"(sdr1));
}
pok_ret_t pok_create_space ( uint8_t  partition_id,
uint32_t  addr,
uint32_t  size 
)

Definition at line 42 of file space.c.

{
#ifdef POK_NEEDS_DEBUG
  printf ("pok_create_space: %d: %x %x\n", partition_id, addr, size);
#endif
  spaces[partition_id].phys_base = addr;
  spaces[partition_id].size = size;

  return (POK_ERRNO_OK);
}

Definition at line 64 of file space.c.

{
   (void) addr;
   return (0);
}
uint32_t pok_space_context_create ( uint8_t  partition_id,
uint32_t  entry_rel,
uint32_t  stack_rel,
uint32_t  arg1,
uint32_t  arg2 
)

Create a new context in the given space

Definition at line 72 of file space.c.

{
  context_t* ctx;
  volatile_context_t* vctx;
  char*      stack_addr;
  (void) partition_id;

  stack_addr = pok_bsp_mem_alloc (KERNEL_STACK_SIZE);

  vctx = (volatile_context_t *)
    (stack_addr + KERNEL_STACK_SIZE - sizeof (volatile_context_t));
  ctx = (context_t *)((char *)vctx - sizeof (context_t) + 8);

  memset (ctx, 0, sizeof (*ctx));
  memset (vctx, 0, sizeof (*vctx));

  vctx->r3     = arg1;
  vctx->r4     = arg2;
  vctx->sp     = stack_rel - 12;
  vctx->srr0   = entry_rel;
  vctx->srr1   = MSR_EE | MSR_IP | MSR_DR | MSR_IR | MSR_PR;
  ctx->lr      = (uint32_t) pok_arch_rfi;

  ctx->sp      = (uint32_t) &vctx->sp;

#ifdef POK_NEEDS_DEBUG
  printf ("space_context_create %d: entry=%x stack=%x arg1=%x arg2=%x ksp=%x\n",
          partition_id, entry_rel, stack_rel, arg1, arg2, &vctx->sp);
#endif

  return (uint32_t)ctx;
}
pok_ret_t pok_space_switch ( uint8_t  old_partition_id,
uint8_t  new_partition_id 
)

Switch from one space to another

Definition at line 55 of file space.c.

{
  (void) old_partition_id;
  /* printf ("space_switch %u -> %u\n", old_partition_id, new_partition_id); */
  asm volatile ("mtsr %0,%1" : : "r"(0), "r"(PPC_SR_KP | new_partition_id));
  return (POK_ERRNO_OK);
}

Variable Documentation

Definition at line 40 of file space.c.