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