1 | /////////////////////////////////////////////////////////////////////////////////// |
---|
2 | // File : mwr_driver.c |
---|
3 | // Date : 27/02/2015 |
---|
4 | // Author : alain greiner |
---|
5 | // Copyright (c) UPMC-LIP6 |
---|
6 | /////////////////////////////////////////////////////////////////////////////////// |
---|
7 | |
---|
8 | #include <giet_config.h> |
---|
9 | #include <hard_config.h> |
---|
10 | #include <mapping_info.h> |
---|
11 | #include <mwr_driver.h> |
---|
12 | #include <utils.h> |
---|
13 | #include <kernel_locks.h> |
---|
14 | #include <tty0.h> |
---|
15 | #include <io.h> |
---|
16 | |
---|
17 | #if !defined(X_SIZE) |
---|
18 | # error: You must define X_SIZE in the hard_config.h file |
---|
19 | #endif |
---|
20 | |
---|
21 | #if !defined(Y_SIZE) |
---|
22 | # error: You must define X_SIZE in the hard_config.h file |
---|
23 | #endif |
---|
24 | |
---|
25 | #if !defined(X_WIDTH) |
---|
26 | # error: You must define X_WIDTH in the hard_config.h file |
---|
27 | #endif |
---|
28 | |
---|
29 | #if !defined(Y_WIDTH) |
---|
30 | # error: You must define X_WIDTH in the hard_config.h file |
---|
31 | #endif |
---|
32 | |
---|
33 | #if !defined(SEG_MWR_BASE) |
---|
34 | # error: You must define SEG_MWR_BASE in the hard_config.h file |
---|
35 | #endif |
---|
36 | |
---|
37 | #if !defined(PERI_CLUSTER_INCREMENT) |
---|
38 | # error: You must define PERI_CLUSTER_INCREMENT in the hard_config.h file |
---|
39 | #endif |
---|
40 | |
---|
41 | |
---|
42 | ///////////////////////////////////////////////////////////////////////////// |
---|
43 | // Global variables |
---|
44 | ///////////////////////////////////////////////////////////////////////////// |
---|
45 | |
---|
46 | __attribute__((section(".kdata"))) |
---|
47 | simple_lock_t _coproc_lock[X_SIZE*Y_SIZE]; |
---|
48 | |
---|
49 | __attribute__((section(".kdata"))) |
---|
50 | unsigned int _coproc_done[X_SIZE*Y_SIZE]; |
---|
51 | |
---|
52 | ///////////////////////////////////////////////////////////////////////////// |
---|
53 | // This function returns the value contained in a private register |
---|
54 | // of the coprocessor contained in cluster "cluster_xy". |
---|
55 | ///////////////////////////////////////////////////////////////////////////// |
---|
56 | unsigned int _mwr_get_coproc_register( unsigned int cluster_xy, // cluster |
---|
57 | unsigned int index ) // register |
---|
58 | { |
---|
59 | unsigned int vaddr = |
---|
60 | SEG_MWR_BASE + |
---|
61 | (cluster_xy * PERI_CLUSTER_INCREMENT) + |
---|
62 | (index << 2); |
---|
63 | |
---|
64 | return ioread32( (void*)vaddr ); |
---|
65 | } |
---|
66 | |
---|
67 | ///////////////////////////////////////////////////////////////////////////// |
---|
68 | // This function sets a new value in a private register |
---|
69 | // of the coprocessor contained in cluster "clustenr_xy". |
---|
70 | ///////////////////////////////////////////////////////////////////////////// |
---|
71 | void _mwr_set_coproc_register( unsigned int cluster_xy, // cluster index |
---|
72 | unsigned int index, // register index |
---|
73 | unsigned int value ) // writte value |
---|
74 | { |
---|
75 | unsigned int vaddr = |
---|
76 | SEG_MWR_BASE + |
---|
77 | (cluster_xy * PERI_CLUSTER_INCREMENT) + |
---|
78 | (index << 2); |
---|
79 | |
---|
80 | iowrite32( (void*)vaddr, value ); |
---|
81 | } |
---|
82 | |
---|
83 | ///////////////////////////////////////////////////////////////////////////// |
---|
84 | // This function returns the value contained in a channel register |
---|
85 | // defined by the "index" and "channel" arguments, in the MWMR_DMA component |
---|
86 | // contained in cluster "cluster_xy". |
---|
87 | ///////////////////////////////////////////////////////////////////////////// |
---|
88 | unsigned int _mwr_get_channel_register( unsigned int cluster_xy, // cluster |
---|
89 | unsigned int channel, // channel |
---|
90 | unsigned int index ) // register |
---|
91 | { |
---|
92 | unsigned int vaddr = |
---|
93 | SEG_MWR_BASE + |
---|
94 | (cluster_xy * PERI_CLUSTER_INCREMENT) + |
---|
95 | ((channel + 1) * (CHANNEL_SPAN << 2)) + |
---|
96 | (index << 2); |
---|
97 | |
---|
98 | return ioread32( (void*)vaddr ); |
---|
99 | } |
---|
100 | |
---|
101 | ///////////////////////////////////////////////////////////////////////////// |
---|
102 | // This function sets a new value in a channel register |
---|
103 | // defined by the "index" and "channel") arguments, in the MWMR_DMA component |
---|
104 | // contained in cluster "cluster_xy". |
---|
105 | ///////////////////////////////////////////////////////////////////////////// |
---|
106 | void _mwr_set_channel_register( unsigned int cluster_xy, // cluster index |
---|
107 | unsigned int channel, // channel index |
---|
108 | unsigned int index, // register index |
---|
109 | unsigned int value ) // written value |
---|
110 | { |
---|
111 | unsigned int vaddr = |
---|
112 | SEG_MWR_BASE + |
---|
113 | (cluster_xy * PERI_CLUSTER_INCREMENT) + |
---|
114 | ((channel + 1) * (CHANNEL_SPAN << 2)) + |
---|
115 | (index << 2); |
---|
116 | |
---|
117 | iowrite32( (void*)vaddr, value ); |
---|
118 | } |
---|
119 | |
---|
120 | /////////////////////////////////////////////////////// |
---|
121 | void _mwr_isr( unsigned int irq_type, // should be HWI |
---|
122 | unsigned int irq_id, // index returned by XCU |
---|
123 | unsigned int channel ) // MWMR_DMA channel |
---|
124 | { |
---|
125 | unsigned int gpid = _get_procid(); |
---|
126 | unsigned int cluster_xy = gpid >> P_WIDTH; |
---|
127 | unsigned int x = cluster_xy >> Y_WIDTH; |
---|
128 | unsigned int y = cluster_xy & ((1<<Y_WIDTH)-1); |
---|
129 | |
---|
130 | // acknowledge IRQ |
---|
131 | _mwr_set_channel_register( cluster_xy, channel, CHANNEL_RUNNING, 0 ); |
---|
132 | |
---|
133 | // compute coproc_id from cluster coordinates |
---|
134 | unsigned int coproc_id = x * Y_SIZE + y; |
---|
135 | |
---|
136 | // set synchronisation variable |
---|
137 | _coproc_done[coproc_id] = 1; |
---|
138 | } |
---|
139 | |
---|
140 | |
---|
141 | |
---|
142 | // Local Variables: |
---|
143 | // tab-width: 4 |
---|
144 | // c-basic-offset: 4 |
---|
145 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
146 | // indent-tabs-mode: nil |
---|
147 | // End: |
---|
148 | // vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
149 | |
---|