source: rtems/bsps/powerpc/mpc8260ads/start/dpram.c @ 9964895

5
Last change on this file since 9964895 was a12dcff8, checked in by Sebastian Huber <sebastian.huber@…>, on Mar 23, 2018 at 3:04:18 PM

bsp/mpc8260: Move libcpu content to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

  • 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  uint8_t       *base;
35  size_t         size;
36  unsigned int   used;
37} dpram_regions[] = {
38/*  { (uint8_t *)&m8260.dpram0[0],    sizeof m8260.dpram0,     0 },*/
39  { (uint8_t *)&m8260.dpram1[0],    sizeof m8260.dpram1,     0 },
40/*  { (uint8_t *)&m8260.dpram2[0],    sizeof m8260.dpram2,     0 },*/
41  { (uint8_t *)&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_Local_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_Local_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.