source: rtems/c/src/lib/libcpu/powerpc/mpc8xx/cpm/dpram.c @ 310a2ec

4.104.114.84.95
Last change on this file since 310a2ec was 8ef3818, checked in by Joel Sherrill <joel.sherrill@…>, on 06/12/00 at 19:57:02

Patch from John Cotton <john.cotton@…>, Charles-Antoine Gauthier
<charles.gauthier@…>, and Darlene A. Stewart
<Darlene.Stewart@…> to add support for a number of very
significant things:

+ BSPs for many variations on the Motorola MBX8xx board series
+ Cache Manager including initial support for m68040

and PowerPC

+ Rework of mpc8xx libcpu code so all mpc8xx CPUs now use

same code base.

+ Rework of eth_comm BSP to utiltize above.

John reports this works on the 821 and 860

  • 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 <bsp.h>
17#include <rtems/rtems/intr.h>
18#include <rtems/error.h>
19
20/*
21 * Allocation order:
22 *      - Dual-Port RAM section 0
23 *      - Dual-Port RAM section 1
24 *      - Dual-Port RAM section 2
25 *      - Dual-Port RAM section 3
26 *      - Dual-Port RAM section 4
27 */
28static struct {
29  unsigned8     *base;
30  unsigned int  size;
31  unsigned int  used;
32} dpram_regions[] = {
33  { (char *)&m8xx.dpram0[0],    sizeof m8xx.dpram0,     0 },
34  { (char *)&m8xx.dpram1[0],    sizeof m8xx.dpram1,     0 },
35  { (char *)&m8xx.dpram2[0],    sizeof m8xx.dpram2,     0 },
36  { (char *)&m8xx.dpram3[0],    sizeof m8xx.dpram3,     0 },
37  { (char *)&m8xx.dpram4[0],    sizeof m8xx.dpram4,     0 },
38};
39
40#define NUM_DPRAM_REGIONS       (sizeof(dpram_regions) / sizeof(dpram_regions[0]))
41
42void *
43m8xx_dpram_allocate( unsigned int byte_count )
44{
45  unsigned int i;
46  ISR_Level level;
47  void *blockp = NULL;
48 
49  byte_count = (byte_count + 3) & ~0x3;
50 
51  /*
52   * Running with interrupts disabled is usually considered bad
53   * form, but this routine is probably being run as part of an
54   * initialization sequence so the effect shouldn't be too severe.
55   */
56  _ISR_Disable (level);
57 
58  for ( i = 0; i < NUM_DPRAM_REGIONS; i++ ) {
59    /*
60     * Verify that the region is available for use.
61     * This test is necessary because if extra microcode modules
62     * are installed, some regions are locked and unavailable.
63     * See MPC860 User's Manual Pages 19-9 to 19-11.
64     */
65    if (dpram_regions[i].used == 0) {
66      volatile unsigned char *cp = dpram_regions[i].base;
67      *cp = 0xAA;
68      if (*cp != 0xAA)
69        dpram_regions[i].used = dpram_regions[i].size;
70      else {
71        *cp = 0x55;
72        if (*cp != 0x55)
73          dpram_regions[i].used = dpram_regions[i].size;
74      }
75      *cp = 0x0;
76    }
77    if (dpram_regions[i].size - dpram_regions[i].used >= byte_count) {
78      blockp = dpram_regions[i].base + dpram_regions[i].used;
79      dpram_regions[i].used += byte_count;
80      break;
81    }
82  }
83 
84  _ISR_Enable(level);
85 
86  if (blockp == NULL)
87    rtems_panic("Can't allocate %d bytes of dual-port RAM.\n", byte_count);
88  return blockp;
89}
Note: See TracBrowser for help on using the repository browser.