Back to home page

LXR

 
 

    


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

0001 /*
0002  * MC68360 buffer descriptor allocation routines
0003  */
0004 
0005 /*
0006  * Copyright (c) 1996 Eric Norum <eric@norum.ca>
0007  */
0008 
0009 #include <rtems.h>
0010 #include <bsp.h>
0011 #include <rtems/m68k/m68360.h>
0012 #include <rtems/error.h>
0013 
0014 /*
0015  * Allocation order:
0016  *  - Dual-Port RAM section 1
0017  *  - Dual-Port RAM section 3
0018  *  - Dual-Port RAM section 0
0019  *  - Dual-Port RAM section 2
0020  */
0021 static struct {
0022     uint8_t        *base;
0023     uint32_t    size;
0024     uint32_t    used;
0025 } bdregions[] = {
0026     { (uint8_t *)&m360.dpram1[0],   sizeof m360.dpram1, 0 },
0027     { (uint8_t *)&m360.dpram3[0],   sizeof m360.dpram3, 0 },
0028     { (uint8_t *)&m360.dpram0[0],   sizeof m360.dpram0, 0 },
0029     { (uint8_t *)&m360.dpram2[0],   sizeof m360.dpram2, 0 },
0030 };
0031 
0032 /*
0033  * Send a command to the CPM RISC processer
0034  */
0035 void *
0036 M360AllocateBufferDescriptors (int count)
0037 {
0038     unsigned int i;
0039     ISR_Level level;
0040     void *bdp = NULL;
0041     unsigned int want = count * sizeof(m360BufferDescriptor_t);
0042 
0043     /*
0044      * Running with interrupts disabled is usually considered bad
0045      * form, but this routine is probably being run as part of an
0046      * initialization sequence so the effect shouldn't be too severe.
0047      */
0048     _ISR_Local_disable (level);
0049     for (i = 0 ; i < sizeof(bdregions) / sizeof(bdregions[0]) ; i++) {
0050         /*
0051          * Verify that the region exists.
0052          * This test is necessary since some chips have
0053          * less dual-port RAM.
0054          */
0055         if (bdregions[i].used == 0) {
0056             volatile uint8_t *cp = bdregions[i].base;
0057             *cp = 0xAA;
0058             if (*cp != 0xAA) {
0059                 bdregions[i].used = bdregions[i].size;
0060                 continue;
0061             }
0062             *cp = 0x55;
0063             if (*cp != 0x55) {
0064                 bdregions[i].used = bdregions[i].size;
0065                 continue;
0066             }
0067             *cp = 0x0;
0068         }
0069         if (bdregions[i].size - bdregions[i].used >= want) {
0070             bdp = bdregions[i].base + bdregions[i].used;
0071             bdregions[i].used += want;
0072             break;
0073         }
0074     }
0075     _ISR_Local_enable (level);
0076     if (bdp == NULL)
0077         rtems_panic ("Can't allocate %d buffer descriptor(s).\n", count);
0078     return bdp;
0079 }
0080 
0081 void *
0082 M360AllocateRiscTimers (int count)
0083 {
0084     /*
0085      * Convert the count to the number of buffer descriptors
0086      * of equal or larger size.  This ensures that all buffer
0087      * descriptors are allocated with appropriate alignment.
0088      */
0089     return M360AllocateBufferDescriptors (((count * 4) +
0090                     sizeof(m360BufferDescriptor_t) - 1) /
0091                     sizeof(m360BufferDescriptor_t));
0092 }