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