source: rtems/bsps/m68k/gen68360/start/alloc360.c @ 753873e5

Last change on this file since 753873e5 was 753873e5, checked in by Joel Sherrill <joel@…>, on 03/22/22 at 20:03:30

Update Eric Norum contact info and start to normalize file headers

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 * MC68360 buffer descriptor allocation routines
3 */
4
5/*
6 * Copyright (c) 1996 Eric Norum <eric@norum.ca>
7 */
8
9#include <rtems.h>
10#include <bsp.h>
11#include <rtems/m68k/m68360.h>
12#include <rtems/error.h>
13
14/*
15 * Allocation order:
16 *      - Dual-Port RAM section 1
17 *      - Dual-Port RAM section 3
18 *      - Dual-Port RAM section 0
19 *      - Dual-Port RAM section 2
20 */
21static struct {
22        uint8_t        *base;
23        uint32_t        size;
24        uint32_t        used;
25} bdregions[] = {
26        { (uint8_t *)&m360.dpram1[0],   sizeof m360.dpram1,     0 },
27        { (uint8_t *)&m360.dpram3[0],   sizeof m360.dpram3,     0 },
28        { (uint8_t *)&m360.dpram0[0],   sizeof m360.dpram0,     0 },
29        { (uint8_t *)&m360.dpram2[0],   sizeof m360.dpram2,     0 },
30};
31
32/*
33 * Send a command to the CPM RISC processer
34 */
35void *
36M360AllocateBufferDescriptors (int count)
37{
38        unsigned int i;
39        ISR_Level level;
40        void *bdp = NULL;
41        unsigned int want = count * sizeof(m360BufferDescriptor_t);
42
43        /*
44         * Running with interrupts disabled is usually considered bad
45         * form, but this routine is probably being run as part of an
46         * initialization sequence so the effect shouldn't be too severe.
47         */
48        _ISR_Local_disable (level);
49        for (i = 0 ; i < sizeof(bdregions) / sizeof(bdregions[0]) ; i++) {
50                /*
51                 * Verify that the region exists.
52                 * This test is necessary since some chips have
53                 * less dual-port RAM.
54                 */
55                if (bdregions[i].used == 0) {
56                        volatile uint8_t *cp = bdregions[i].base;
57                        *cp = 0xAA;
58                        if (*cp != 0xAA) {
59                                bdregions[i].used = bdregions[i].size;
60                                continue;
61                        }
62                        *cp = 0x55;
63                        if (*cp != 0x55) {
64                                bdregions[i].used = bdregions[i].size;
65                                continue;
66                        }
67                        *cp = 0x0;
68                }
69                if (bdregions[i].size - bdregions[i].used >= want) {
70                        bdp = bdregions[i].base + bdregions[i].used;
71                        bdregions[i].used += want;
72                        break;
73                }
74        }
75        _ISR_Local_enable (level);
76        if (bdp == NULL)
77                rtems_panic ("Can't allocate %d buffer descriptor(s).\n", count);
78        return bdp;
79}
80
81void *
82M360AllocateRiscTimers (int count)
83{
84        /*
85         * Convert the count to the number of buffer descriptors
86         * of equal or larger size.  This ensures that all buffer
87         * descriptors are allocated with appropriate alignment.
88         */
89        return M360AllocateBufferDescriptors (((count * 4) +
90                                        sizeof(m360BufferDescriptor_t) - 1) /
91                                        sizeof(m360BufferDescriptor_t));
92}
Note: See TracBrowser for help on using the repository browser.