source: rtems/c/src/lib/libcpu/powerpc/mpc8xx/cpm/dpram.c @ 73b5bd5d

4.104.114.84.95
Last change on this file since 73b5bd5d was 66c373bf, checked in by Ralf Corsepius <ralf.corsepius@…>, on 03/31/04 at 02:04:00

2004-03-30 Ralf Corsepius <ralf_corsepius@…>

  • mpc505/timer/timer.c, mpc5xx/timer/timer.c, mpc6xx/clock/c_clock.c, mpc6xx/timer/timer.c, mpc8260/clock/clock.c, mpc8260/console-generic/console-generic.c, mpc8260/cpm/cp.c, mpc8260/cpm/dpram.c, mpc8260/include/cpm.h, mpc8260/include/mmu.h, mpc8260/include/mpc8260.h, mpc8260/mmu/mmu.c, mpc8260/timer/timer.c, mpc8xx/clock/clock.c, mpc8xx/console-generic/console-generic.c, mpc8xx/cpm/cp.c, mpc8xx/cpm/dpram.c, mpc8xx/include/cpm.h, mpc8xx/include/mmu.h, mpc8xx/include/mpc8xx.h, mpc8xx/mmu/mmu.c, mpc8xx/timer/timer.c, ppc403/clock/clock.c, ppc403/console/console.c, ppc403/console/console405.c, ppc403/ictrl/ictrl.c, ppc403/ictrl/ictrl.h, ppc403/timer/timer.c, ppc403/tty_drv/tty_drv.c, rtems/powerpc/cache.h, shared/src/cache.c: Convert to using c99 fixed size types.
  • Property mode set to 100644
File size: 2.4 KB
Line 
1/*
2 * dpram.c
3 *
4 * MPC8xx dual-port RAM allocation routines
5 *
6 * Based on code (alloc860.c in eth_comm port) by
7 * Jay Monkman (jmonkman@frasca.com),
8 * which, in turn, is based on code by
9 * W. Eric Norum (eric@skatter.usask.ca).
10 *
11 *
12 * Modifications :
13 * Copyright (c) 1999, National Research Council of Canada
14 */
15
16#include <rtems.h>
17#include <mpc8xx.h>
18#include <mpc8xx/cpm.h>
19
20extern void rtems_panic(char *, int);
21
22/*
23 * Allocation order:
24 *      - Dual-Port RAM section 0
25 *      - Dual-Port RAM section 1
26 *      - Dual-Port RAM section 2
27 *      - Dual-Port RAM section 3
28 *      - Dual-Port RAM section 4
29 */
30static struct {
31  uint8_t       *base;
32  unsigned int  size;
33  unsigned int  used;
34} dpram_regions[] = {
35  { (char *)&m8xx.dpram0[0],    sizeof m8xx.dpram0,     0 },
36  { (char *)&m8xx.dpram1[0],    sizeof m8xx.dpram1,     0 },
37  { (char *)&m8xx.dpram2[0],    sizeof m8xx.dpram2,     0 },
38  { (char *)&m8xx.dpram3[0],    sizeof m8xx.dpram3,     0 },
39  { (char *)&m8xx.dpram4[0],    sizeof m8xx.dpram4,     0 },
40};
41
42#define NUM_DPRAM_REGIONS       (sizeof(dpram_regions) / sizeof(dpram_regions[0]))
43
44void *
45m8xx_dpram_allocate( unsigned int byte_count )
46{
47  unsigned int i;
48  ISR_Level level;
49  void *blockp = NULL;
50 
51  byte_count = (byte_count + 3) & ~0x3;
52 
53  /*
54   * Running with interrupts disabled is usually considered bad
55   * form, but this routine is probably being run as part of an
56   * initialization sequence so the effect shouldn't be too severe.
57   */
58  _ISR_Disable (level);
59 
60  for ( i = 0; i < NUM_DPRAM_REGIONS; i++ ) {
61    /*
62     * Verify that the region is available for use.
63     * This test is necessary because if extra microcode modules
64     * are installed, some regions are locked and unavailable.
65     * See MPC860 User's Manual Pages 19-9 to 19-11.
66     */
67    if (dpram_regions[i].used == 0) {
68      volatile unsigned char *cp = dpram_regions[i].base;
69      *cp = 0xAA;
70      if (*cp != 0xAA)
71        dpram_regions[i].used = dpram_regions[i].size;
72      else {
73        *cp = 0x55;
74        if (*cp != 0x55)
75          dpram_regions[i].used = dpram_regions[i].size;
76      }
77      *cp = 0x0;
78    }
79    if (dpram_regions[i].size - dpram_regions[i].used >= byte_count) {
80      blockp = dpram_regions[i].base + dpram_regions[i].used;
81      dpram_regions[i].used += byte_count;
82      break;
83    }
84  }
85 
86  _ISR_Enable(level);
87 
88  if (blockp == NULL)
89    rtems_panic("Can't allocate %d bytes of dual-port RAM.\n", byte_count);
90  return blockp;
91}
Note: See TracBrowser for help on using the repository browser.