1 |
2 |
drasko |
#! /usr/bin/env python2.6
|
2 |
|
|
# -*- mode: python; coding: utf-8; -*-
|
3 |
|
|
import os, sys, shelve, shutil, re
|
4 |
|
|
from projpaths import *
|
5 |
|
|
from lib import *
|
6 |
|
|
from caps import *
|
7 |
|
|
from string import Template
|
8 |
|
|
|
9 |
|
|
cap_strings = { 'ipc' : \
|
10 |
|
|
'''
|
11 |
|
|
\t\t\t[${idx}] = {
|
12 |
|
|
\t\t\t\t.target = ${cid},
|
13 |
|
|
\t\t\t\t.type = CAP_TYPE_IPC | ${target_rtype},
|
14 |
|
|
\t\t\t\t.access = CAP_IPC_SEND | CAP_IPC_RECV
|
15 |
|
|
\t\t\t\t | CAP_IPC_FULL | CAP_IPC_SHORT
|
16 |
|
|
\t\t\t\t | CAP_IPC_EXTENDED | CAP_CHANGEABLE
|
17 |
|
|
\t\t\t\t | CAP_REPLICABLE | CAP_TRANSFERABLE,
|
18 |
|
|
\t\t\t\t.start = 0, .end = 0, .size = 0,
|
19 |
|
|
\t\t\t},
|
20 |
|
|
'''
|
21 |
|
|
, 'tctrl' : \
|
22 |
|
|
'''
|
23 |
|
|
\t\t\t[${idx}] = {
|
24 |
|
|
\t\t\t\t.target = ${cid},
|
25 |
|
|
\t\t\t\t.type = CAP_TYPE_TCTRL | ${target_rtype},
|
26 |
|
|
\t\t\t\t.access = CAP_TCTRL_CREATE | CAP_TCTRL_DESTROY
|
27 |
|
|
\t\t\t\t | CAP_TCTRL_SUSPEND | CAP_TCTRL_RUN
|
28 |
|
|
\t\t\t\t | CAP_TCTRL_RECYCLE | CAP_TCTRL_WAIT
|
29 |
|
|
\t\t\t\t | CAP_CHANGEABLE | CAP_REPLICABLE
|
30 |
|
|
\t\t\t\t | CAP_TRANSFERABLE,
|
31 |
|
|
\t\t\t\t.start = 0, .end = 0, .size = 0,
|
32 |
|
|
\t\t\t},
|
33 |
|
|
'''
|
34 |
|
|
, 'irqctrl' : \
|
35 |
|
|
'''
|
36 |
|
|
\t\t\t[${idx}] = {
|
37 |
|
|
\t\t\t\t.target = ${cid},
|
38 |
|
|
\t\t\t\t.type = CAP_TYPE_IRQCTRL | ${target_rtype},
|
39 |
|
|
\t\t\t\t.access = CAP_IRQCTRL_REGISTER | CAP_IRQCTRL_WAIT
|
40 |
|
|
\t\t\t\t | CAP_CHANGEABLE | CAP_REPLICABLE
|
41 |
|
|
\t\t\t\t | CAP_TRANSFERABLE,
|
42 |
|
|
\t\t\t\t.start = 0, .end = 0, .size = 0,
|
43 |
|
|
\t\t\t},
|
44 |
|
|
'''
|
45 |
|
|
, 'exregs' : \
|
46 |
|
|
'''
|
47 |
|
|
\t\t\t[${idx}] = {
|
48 |
|
|
\t\t\t\t.target = ${cid},
|
49 |
|
|
\t\t\t\t.type = CAP_TYPE_EXREGS | ${target_rtype},
|
50 |
|
|
\t\t\t\t.access = CAP_EXREGS_RW_PAGER
|
51 |
|
|
\t\t\t\t | CAP_EXREGS_RW_UTCB | CAP_EXREGS_RW_SP
|
52 |
|
|
\t\t\t\t | CAP_EXREGS_RW_PC | CAP_EXREGS_RW_REGS
|
53 |
|
|
\t\t\t\t | CAP_CHANGEABLE | CAP_REPLICABLE | CAP_TRANSFERABLE,
|
54 |
|
|
\t\t\t\t.start = 0, .end = 0, .size = 0,
|
55 |
|
|
\t\t\t},
|
56 |
|
|
'''
|
57 |
|
|
, 'capctrl' : \
|
58 |
|
|
'''
|
59 |
|
|
\t\t\t[${idx}] = {
|
60 |
|
|
\t\t\t\t.target = ${cid},
|
61 |
|
|
\t\t\t\t.type = CAP_TYPE_CAP | ${target_rtype},
|
62 |
|
|
\t\t\t\t.access = CAP_CAP_GRANT | CAP_CAP_READ
|
63 |
|
|
\t\t\t\t | CAP_CAP_SHARE | CAP_CAP_REPLICATE
|
64 |
|
|
\t\t\t\t | CAP_CAP_MODIFY
|
65 |
|
|
\t\t\t\t| CAP_CAP_READ | CAP_CAP_SHARE,
|
66 |
|
|
\t\t\t\t.start = 0, .end = 0, .size = 0,
|
67 |
|
|
\t\t\t},
|
68 |
|
|
'''
|
69 |
|
|
, 'umutex' : \
|
70 |
|
|
'''
|
71 |
|
|
\t\t\t[${idx}] = {
|
72 |
|
|
\t\t\t\t.target = ${cid},
|
73 |
|
|
\t\t\t\t.type = CAP_TYPE_UMUTEX | CAP_RTYPE_CONTAINER,
|
74 |
|
|
\t\t\t\t.access = CAP_UMUTEX_LOCK | CAP_UMUTEX_UNLOCK,
|
75 |
|
|
\t\t\t\t.start = 0, .end = 0, .size = 0,
|
76 |
|
|
\t\t\t},
|
77 |
|
|
'''
|
78 |
|
|
, 'threadpool' : \
|
79 |
|
|
'''
|
80 |
|
|
\t\t\t[${idx}] = {
|
81 |
|
|
\t\t\t\t.target = ${cid},
|
82 |
|
|
\t\t\t\t.type = CAP_TYPE_QUANTITY
|
83 |
|
|
\t\t\t\t | CAP_RTYPE_THREADPOOL,
|
84 |
|
|
\t\t\t\t.access = CAP_CHANGEABLE | CAP_TRANSFERABLE,
|
85 |
|
|
\t\t\t\t.start = 0, .end = 0,
|
86 |
|
|
\t\t\t\t.size = ${size},
|
87 |
|
|
\t\t\t},
|
88 |
|
|
'''
|
89 |
|
|
, 'spacepool' : \
|
90 |
|
|
'''
|
91 |
|
|
\t\t\t[${idx}] = {
|
92 |
|
|
\t\t\t\t.target = ${cid},
|
93 |
|
|
\t\t\t\t.type = CAP_TYPE_QUANTITY | CAP_RTYPE_SPACEPOOL,
|
94 |
|
|
\t\t\t\t.access = CAP_CHANGEABLE | CAP_TRANSFERABLE,
|
95 |
|
|
\t\t\t\t.start = 0, .end = 0,
|
96 |
|
|
\t\t\t\t.size = ${size},
|
97 |
|
|
\t\t\t},
|
98 |
|
|
'''
|
99 |
|
|
, 'cpupool' : \
|
100 |
|
|
'''
|
101 |
|
|
\t\t\t[${idx}] = {
|
102 |
|
|
\t\t\t\t.target = ${cid},
|
103 |
|
|
\t\t\t\t.type = CAP_TYPE_QUANTITY | CAP_RTYPE_CPUPOOL,
|
104 |
|
|
\t\t\t\t.access = 0, .start = 0, .end = 0,
|
105 |
|
|
\t\t\t\t.size = ${size} /* Percentage */,
|
106 |
|
|
\t\t\t},
|
107 |
|
|
'''
|
108 |
|
|
, 'mutexpool' : \
|
109 |
|
|
'''
|
110 |
|
|
\t\t\t[${idx}] = {
|
111 |
|
|
\t\t\t\t.target = ${cid},
|
112 |
|
|
\t\t\t\t.type = CAP_TYPE_QUANTITY | CAP_RTYPE_MUTEXPOOL,
|
113 |
|
|
\t\t\t\t.access = CAP_CHANGEABLE | CAP_TRANSFERABLE,
|
114 |
|
|
\t\t\t\t.start = 0, .end = 0,
|
115 |
|
|
\t\t\t\t.size = ${size},
|
116 |
|
|
\t\t\t},
|
117 |
|
|
'''
|
118 |
|
|
, 'mappool' : \
|
119 |
|
|
'''
|
120 |
|
|
\t\t\t[${idx}] = {
|
121 |
|
|
\t\t\t\t/* For pmd accounting */
|
122 |
|
|
\t\t\t\t.target = ${cid},
|
123 |
|
|
\t\t\t\t.type = CAP_TYPE_QUANTITY | CAP_RTYPE_MAPPOOL,
|
124 |
|
|
\t\t\t\t.access = CAP_CHANGEABLE | CAP_TRANSFERABLE,
|
125 |
|
|
\t\t\t\t.start = 0, .end = 0,
|
126 |
|
|
\t\t\t\t/* Function of mem regions, nthreads etc. */
|
127 |
|
|
\t\t\t\t.size = ${size},
|
128 |
|
|
\t\t\t},
|
129 |
|
|
'''
|
130 |
|
|
, 'cappool' : \
|
131 |
|
|
'''
|
132 |
|
|
\t\t\t[${idx}] = {
|
133 |
|
|
\t\t\t\t/* For cap spliting, creating, etc. */
|
134 |
|
|
\t\t\t\t.target = ${cid},
|
135 |
|
|
\t\t\t\t.type = CAP_TYPE_QUANTITY | CAP_RTYPE_CAPPOOL,
|
136 |
|
|
\t\t\t\t.access = CAP_CHANGEABLE | CAP_TRANSFERABLE,
|
137 |
|
|
\t\t\t\t.start = 0, .end = 0,
|
138 |
|
|
\t\t\t\t/* This may be existing caps X 2 etc. */
|
139 |
|
|
\t\t\t\t.size = ${size},
|
140 |
|
|
\t\t\t},
|
141 |
|
|
'''
|
142 |
|
|
, 'device' : \
|
143 |
|
|
'''
|
144 |
|
|
\t\t\t[${idx}] = {
|
145 |
|
|
\t\t\t\t/* For device selection */
|
146 |
|
|
\t\t\t\t.target = ${cid},
|
147 |
|
|
\t\t\t\t.type = CAP_TYPE_MAP_PHYSMEM | CAP_RTYPE_CONTAINER,
|
148 |
|
|
\t\t\t\t.access = CAP_MAP_READ | CAP_MAP_WRITE | CAP_MAP_EXEC |
|
149 |
|
|
\t\t\t\t\tCAP_MAP_CACHED | CAP_MAP_UNCACHED | CAP_MAP_UNMAP |
|
150 |
|
|
\t\t\t\t\tCAP_IRQCTRL_REGISTER,
|
151 |
|
|
\t\t\t\t.start = __pfn(PLATFORM_${devname}_BASE),
|
152 |
|
|
\t\t\t\t.end = __pfn(PLATFORM_${devname}_BASE + PLATFORM_${devname}_SIZE),
|
153 |
|
|
\t\t\t\t.size = PLATFORM_${devname}_SIZE >> 12,
|
154 |
|
|
\t\t\t\t.attr = (CAP_DEVTYPE_${devtype} & CAP_DEVTYPE_MASK)
|
155 |
|
|
\t\t\t\t\t| ((${devnum} << CAP_DEVNUM_SHIFT) & CAP_DEVNUM_MASK),
|
156 |
|
|
\t\t\t\t.irq = IRQ_${devname},
|
157 |
|
|
\t\t\t},
|
158 |
|
|
'''
|
159 |
|
|
}
|
160 |
|
|
|
161 |
|
|
#
|
162 |
|
|
# These are carefully crafted functions, touch with care.
|
163 |
|
|
#
|
164 |
|
|
def prepare_custom_capability(cont, param, val):
|
165 |
|
|
if 'TYPE' in param:
|
166 |
|
|
capkey, captype, rest = param.split('_', 2)
|
167 |
|
|
capkey = capkey.lower()
|
168 |
|
|
captype = captype.lower()
|
169 |
|
|
cont.caps[capkey] = cap_strings[captype]
|
170 |
|
|
elif 'TARGET' in param:
|
171 |
|
|
target_parts = param.split('_', 2)
|
172 |
|
|
if len(target_parts) == 2:
|
173 |
|
|
capkey = target_parts[0].lower()
|
174 |
|
|
templ = Template(cont.caps[capkey])
|
175 |
|
|
cont.caps[capkey] = templ.safe_substitute(cid = val)
|
176 |
|
|
elif len(target_parts) == 3:
|
177 |
|
|
capkey = target_parts[0].lower()
|
178 |
|
|
ttype = target_parts[2]
|
179 |
|
|
templ = Template(cont.caps[capkey])
|
180 |
|
|
|
181 |
|
|
# On current container, provide correct rtype and current containerid.
|
182 |
|
|
# Else we leave container id to user-supplied value
|
183 |
|
|
if ttype == 'CURRENT_CONTAINER':
|
184 |
|
|
cont.caps[capkey] = templ.safe_substitute(target_rtype = 'CAP_RTYPE_CONTAINER',
|
185 |
|
|
cid = cont.id)
|
186 |
|
|
elif ttype == 'CURRENT_PAGER_SPACE':
|
187 |
|
|
cont.caps[capkey] = templ.safe_substitute(target_rtype = 'CAP_RTYPE_SPACE',
|
188 |
|
|
cid = cont.id)
|
189 |
|
|
elif ttype == 'ANOTHER_CONTAINER':
|
190 |
|
|
cont.caps[capkey] = templ.safe_substitute(target_rtype = 'CAP_RTYPE_CONTAINER')
|
191 |
|
|
elif ttype == 'ANOTHER_PAGER':
|
192 |
|
|
cont.caps[capkey] = templ.safe_substitute(target_rtype = 'CAP_RTYPE_THREAD')
|
193 |
|
|
elif 'DEVICE' in param:
|
194 |
|
|
# Extract all fields
|
195 |
|
|
unused, device_name, rest = param.split('_', 2)
|
196 |
|
|
capkey = device_name.lower()
|
197 |
|
|
cont.caps[capkey] = cap_strings['device']
|
198 |
|
|
templ = Template(cont.caps[capkey])
|
199 |
|
|
device_id = device_name[-1:]
|
200 |
|
|
device_type = device_name[:-1]
|
201 |
|
|
|
202 |
|
|
# Fill in all blanks
|
203 |
|
|
cont.caps[capkey] = \
|
204 |
|
|
templ.safe_substitute(cid = cont.id,
|
205 |
|
|
devname = device_name,
|
206 |
|
|
devnum = device_id,
|
207 |
|
|
devtype = device_type)
|
208 |
|
|
|
209 |
|
|
else: # Ignore custom_use symbol
|
210 |
|
|
return
|
211 |
|
|
# print capkey
|
212 |
|
|
# print cont.caps[capkey]
|
213 |
|
|
|
214 |
|
|
def prepare_typed_capability(cont, param, val):
|
215 |
|
|
captype, params = param.split('_', 1)
|
216 |
|
|
captype = captype.lower()
|
217 |
|
|
|
218 |
|
|
# USE makes us assign the initial cap string with blank fields
|
219 |
|
|
if 'USE' in params:
|
220 |
|
|
cont.caps[captype] = cap_strings[captype]
|
221 |
|
|
|
222 |
|
|
# Prepare string template from capability type
|
223 |
|
|
templ = Template(cont.caps[captype])
|
224 |
|
|
|
225 |
|
|
# If it is a pool, amend current container id as default
|
226 |
|
|
if captype[-len('pool'):] == 'pool':
|
227 |
|
|
cont.caps[captype] = templ.safe_substitute(cid = cont.id)
|
228 |
|
|
|
229 |
|
|
# Fill in the blank size field
|
230 |
|
|
elif 'SIZE' in params:
|
231 |
|
|
# Get reference to capability string template
|
232 |
|
|
templ = Template(cont.caps[captype])
|
233 |
|
|
cont.caps[captype] = templ.safe_substitute(size = val)
|
234 |
|
|
|
235 |
|
|
# Fill in capability target type and target id fields
|
236 |
|
|
elif 'TARGET' in params:
|
237 |
|
|
# Get reference to capability string template
|
238 |
|
|
templ = Template(cont.caps[captype])
|
239 |
|
|
|
240 |
|
|
# Two types of strings are expected here: TARGET or TARGET_TARGETTYPE
|
241 |
|
|
# If TARGET, the corresponding value is in val
|
242 |
|
|
target_parts = params.split('_', 1)
|
243 |
|
|
|
244 |
|
|
# Target type
|
245 |
|
|
if len(target_parts) == 2:
|
246 |
|
|
ttype = target_parts[1]
|
247 |
|
|
|
248 |
|
|
# On current container, provide correct rtype and current containerid.
|
249 |
|
|
# Else we leave container id to user-supplied value
|
250 |
|
|
if ttype == 'CURRENT_CONTAINER':
|
251 |
|
|
cont.caps[captype] = templ.safe_substitute(target_rtype = 'CAP_RTYPE_CONTAINER',
|
252 |
|
|
cid = cont.id)
|
253 |
|
|
elif ttype == 'CURRENT_PAGER_SPACE':
|
254 |
|
|
cont.caps[captype] = templ.safe_substitute(target_rtype = 'CAP_RTYPE_SPACE',
|
255 |
|
|
cid = cont.id)
|
256 |
|
|
elif ttype == 'ANOTHER_CONTAINER':
|
257 |
|
|
cont.caps[captype] = templ.safe_substitute(target_rtype = 'CAP_RTYPE_CONTAINER')
|
258 |
|
|
elif ttype == 'ANOTHER_PAGER':
|
259 |
|
|
cont.caps[captype] = templ.safe_substitute(target_rtype = 'CAP_RTYPE_THREAD')
|
260 |
|
|
|
261 |
|
|
# Get target value supplied by user in val
|
262 |
|
|
else:
|
263 |
|
|
cont.caps[captype] = templ.safe_substitute(cid = val)
|
264 |
|
|
|
265 |
|
|
#print captype
|
266 |
|
|
#print cont.caps[captype]
|
267 |
|
|
|
268 |
|
|
def prepare_capability(cont, param, val):
|
269 |
|
|
if 'CUSTOM' in param or 'DEVICE' in param:
|
270 |
|
|
prepare_custom_capability(cont, param, val)
|
271 |
|
|
else:
|
272 |
|
|
prepare_typed_capability(cont, param, val)
|
273 |
|
|
|