Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:59

0001 /*
0002  * dpram.c
0003  *
0004  * MPC8xx dual-port RAM allocation routines
0005  *
0006  * Based on code (alloc860.c in eth_comm port) by
0007  * Jay Monkman (jmonkman@frasca.com),
0008  * which, in turn, is based on code by
0009  * W. Eric Norum (eric@norum.ca).
0010  *
0011  *
0012  * Modifications :
0013  * Copyright (c) 1999, National Research Council of Canada
0014  */
0015 
0016 #include <rtems.h>
0017 #include <rtems/error.h>
0018 
0019 #include <mpc8xx.h>
0020 #include <mpc8xx/cpm.h>
0021 
0022 /*
0023  * Allocation order:
0024  *      - Dual-Port RAM section 0
0025  *      - Dual-Port RAM section 1
0026  *      - Dual-Port RAM section 2
0027  *      - Dual-Port RAM section 3
0028  *      - Dual-Port RAM section 4
0029  */
0030 static struct {
0031   uint8_t       *base;
0032   size_t     size;
0033   unsigned int   used;
0034 } dpram_regions[] = {
0035   { (uint8_t *) &m8xx.dpram0[0],    sizeof m8xx.dpram0,     0 },
0036   { (uint8_t *) &m8xx.dpram1[0],    sizeof m8xx.dpram1,     0 },
0037   { (uint8_t *) &m8xx.dpram2[0],    sizeof m8xx.dpram2,     0 },
0038   { (uint8_t *) &m8xx.dpram3[0],    sizeof m8xx.dpram3,     0 },
0039   { (uint8_t *) &m8xx.dpram4[0],    sizeof m8xx.dpram4,     0 },
0040 };
0041 
0042 #define NUM_DPRAM_REGIONS   (sizeof(dpram_regions) / sizeof(dpram_regions[0]))
0043 
0044 void *
0045 m8xx_dpram_allocate( unsigned int byte_count )
0046 {
0047   unsigned int i;
0048   ISR_Level level;
0049   void *blockp = NULL;
0050 
0051   byte_count = (byte_count + 3) & ~0x3;
0052 
0053   /*
0054    * Running with interrupts disabled is usually considered bad
0055    * form, but this routine is probably being run as part of an
0056    * initialization sequence so the effect shouldn't be too severe.
0057    */
0058   _ISR_Local_disable (level);
0059 
0060   for ( i = 0; i < NUM_DPRAM_REGIONS; i++ ) {
0061     /*
0062      * Verify that the region is available for use.
0063      * This test is necessary because if extra microcode modules
0064      * are installed, some regions are locked and unavailable.
0065      * See MPC860 User's Manual Pages 19-9 to 19-11.
0066      */
0067     if (dpram_regions[i].used == 0) {
0068       volatile unsigned char *cp = dpram_regions[i].base;
0069       *cp = 0xAA;
0070       if (*cp != 0xAA)
0071         dpram_regions[i].used = dpram_regions[i].size;
0072       else {
0073         *cp = 0x55;
0074         if (*cp != 0x55)
0075           dpram_regions[i].used = dpram_regions[i].size;
0076       }
0077       *cp = 0x0;
0078     }
0079     if (dpram_regions[i].size - dpram_regions[i].used >= byte_count) {
0080       blockp = dpram_regions[i].base + dpram_regions[i].used;
0081       dpram_regions[i].used += byte_count;
0082       break;
0083     }
0084   }
0085 
0086   _ISR_Local_enable(level);
0087 
0088   if (blockp == NULL)
0089     rtems_panic("Can't allocate %d bytes of dual-port RAM.\n", byte_count);
0090   return blockp;
0091 }