annotate TaskManager/kernel/ppe/DmaBuffer.cc @ 88:504899860e66

*** empty log message ***
author gongo
date Wed, 27 Feb 2008 17:16:29 +0900
parents 61bacd3b4405
children 1733f3cbfa28
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
54
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
1 #include <stdio.h>
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
2 #include <stdlib.h>
70
178459e03f5c *** empty log message ***
gongo
parents: 55
diff changeset
3 #include "types.h"
54
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
4 #include "DmaBuffer.h"
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
5
88
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
6 #define ALIGN_DOWN(v, align) ((v)&(-align))
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
7 #define ALIGN_UP(v, align) ALIGN_DOWN((v)+((align)-1), align)
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
8
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
9 void*
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
10 new_align(int alignment, int size)
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
11 {
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
12 char *nonalign;
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
13 char *align;
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
14
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
15 nonalign = new char[size + sizeof(void*) + alignment - 1];
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
16 align = (char*)(ALIGN_UP((unsigned int)nonalign+sizeof(void*),alignment));
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
17 *((void**)align - 1) = (void*)nonalign;
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
18
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
19 return align;
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
20 }
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
21
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
22 void
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
23 free_align(void *ptr)
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
24 {
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
25 char *real;
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
26
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
27 if (ptr != NULL) {
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
28 real = (char*)(*((void**)(ptr)-1));
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
29 delete real;
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
30 }
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
31 }
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
32
54
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
33 DmaBuffer::DmaBuffer(int size)
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
34 {
86
61bacd3b4405 *** empty log message ***
gongo
parents: 70
diff changeset
35 buffer[0] = malloc(size);
61bacd3b4405 *** empty log message ***
gongo
parents: 70
diff changeset
36 buffer[1] = malloc(size);
70
178459e03f5c *** empty log message ***
gongo
parents: 55
diff changeset
37
86
61bacd3b4405 *** empty log message ***
gongo
parents: 70
diff changeset
38 //posix_memalign(&buffer[0], DEFAULT_ALIGNMENT, size);
61bacd3b4405 *** empty log message ***
gongo
parents: 70
diff changeset
39 //posix_memalign(&buffer[1], DEFAULT_ALIGNMENT, size);
70
178459e03f5c *** empty log message ***
gongo
parents: 55
diff changeset
40
88
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
41 //buffer[0] = new_align(DEFAULT_ALIGNMENT, size);
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
42 //buffer[1] = new_align(DEFAULT_ALIGNMENT, size);
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
43
54
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
44 flag = 0;
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
45 }
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
46
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
47 DmaBuffer::~DmaBuffer(void)
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
48 {
88
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
49 //free(buffer[0]);
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
50 //free(buffer[1]);
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
51 free_align(buffer[0]);
504899860e66 *** empty log message ***
gongo
parents: 86
diff changeset
52 free_align(buffer[1]);
54
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
53 }
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
54
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
55 void
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
56 DmaBuffer::swap_buffer(void)
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
57 {
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
58 flag ^= 1;
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
59 }
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
60
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
61 void
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
62 DmaBuffer::get_buffer(void *_dst)
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
63 {
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
64 void **dst = (void**)_dst;
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
65 *dst = buffer[flag];
90523ccc4dff *** empty log message ***
gongo
parents:
diff changeset
66 }