source: rtems/c/src/lib/libcpu/powerpc/mpc8xx/cpm/dpram.c @ 8c46a690

4.104.114.84.9
Last change on this file since 8c46a690 was 8c46a690, checked in by Ralf Corsepius <ralf.corsepius@…>, on Feb 11, 2005 at 3:51:44 PM

2005-02-11 Ralf Corsepius <ralf.corsepius@…>

  • mpc8260/cpm/dpram.c, mpc8xx/cpm/dpram.c: Remove local rtems_panic, use #include <rtems/error.h>.
  • 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 <rtems/error.h>
18
19#include <mpc8xx.h>
20#include <mpc8xx/cpm.h>
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  char          *base;
32  size_t         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.