source: rtems/c/src/lib/libcpu/powerpc/mpc8260/cpm/dpram.c @ 16ae480

4.104.114.84.95
Last change on this file since 16ae480 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.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 <mpc8260.h>
22#include <mpc8260/cpm.h>
23
24void rtems_panic(char *, int);
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  uint8_t       *base;
35  unsigned int  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.