1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:
46:
47: 48: 49: 50:
51:
52: #include <typedef.h>
53: #include "sysmgr.h"
54: #include "segmgr.h"
55: #include "excmgr.h"
56: #include "cache_info.h"
57: #include "pagedef.h"
58: #include <sys/segment.h>
59: #include <sys/svc/ifsegment.h>
60:
61: 62: 63: 64: 65:
66: EXPORT FastLock SegLock = { -1, -1 };
67:
68: 69: 70:
71: LOCAL ER _GetSpaceInfo( CONST void *addr, INT len, T_SPINFO *pk_spinfo )
72: {
73: T_RSMB rsmb;
74: ER ercd = E_OK;
75:
76: if ( len <= 0 ) {
77: ercd = E_PAR;
78: goto err_ret;
79: }
80: ercd = ChkSpaceR(addr, len);
81: if ( ercd < E_OK ){
82: goto err_ret;
83: }
84:
85: ercd = RefSysMemInfo(&rsmb);
86: if ( ercd < E_OK ) {
87: goto err_ret;
88: }
89:
90: pk_spinfo->paddr = toPhysicalAddress(addr);
91: pk_spinfo->page = (void*)((UW)(pk_spinfo->paddr) & ~(rsmb.blksz-1));
92: pk_spinfo->pagesz = rsmb.blksz;
93: pk_spinfo->cachesz = GetCacheLineSize();
94:
95: 96: 97:
98: pk_spinfo->cont = len;
99:
100: return ercd;
101:
102: err_ret:
103: TM_DEBUG_PRINT(("_GetSpaceInfo ercd = %d\n", ercd));
104: return ercd;
105: }
106:
107:
108:
109: 110: 111: 112: 113: 114: 115: 116: 117:
118: LOCAL ER _MapMemory( CONST void *paddr, INT len, UINT attr, void **laddr )
119: {
120: ER ercd;
121: UINT a;
122:
123: if ( len <= 0 ) {
124: ercd = E_PAR;
125: goto err_ret;
126: }
127:
128: a = ( (attr & MM_USER) != 0 )? TA_RNG3: TA_RNG0;
129: if ( (attr & MM_CDIS) != 0 ) {
130: a |= TA_NOCACHE;
131: }
132:
133: if ( paddr == NULL ) {
134:
135: *laddr = GetSysMemBlk((INT)smPageCount((UW)len), a);
136: if ( *laddr == NULL ) {
137: ercd = E_NOMEM;
138: goto err_ret;
139: }
140:
141:
142: ercd = _SetMemoryAccess(*laddr, len, (attr & (MM_READ|MM_WRITE|MM_EXECUTE)));
143: if ( ercd < E_OK ) {
144: RelSysMemBlk(*laddr);
145: *laddr = NULL;
146: goto err_ret;
147: }
148:
149: } else {
150:
151: *laddr = toLogicalAddress(paddr);
152:
153:
154: FlushCache(*laddr, len);
155:
156: if ( (attr & MM_CDIS) != 0 ) {
157:
158: *laddr = toNoCacheLogicalAddress(*laddr);
159: }
160: }
161:
162: return E_OK;
163:
164: err_ret:
165: TM_DEBUG_PRINT(("_MapMemory ercd = %d\n", ercd));
166: return ercd;
167: }
168:
169: 170: 171:
172: LOCAL ER _UnmapMemory( CONST void *laddr )
173: {
174: ER ercd;
175:
176: 177: 178: 179:
180: ercd = RelSysMemBlk(laddr);
181: if ( ercd < E_OK && ercd != E_PAR ) {
182: goto err_ret;
183: }
184:
185: return E_OK;
186:
187: err_ret:
188: TM_DEBUG_PRINT(("_UnmapMemory ercd = %d\n", ercd));
189: return ercd;
190: }
191:
192:
193:
194: 195: 196:
197: LOCAL ER _FlushMemCache( void *laddr, INT len, UINT mode )
198: {
199: ER ercd;
200:
201: if ( (mode & ~(TCM_ICACHE|TCM_DCACHE)) != 0 ) {
202: ercd = E_PAR;
203: goto err_ret;
204: }
205: ercd = ChkSpaceR(laddr, len);
206: if ( ercd < E_OK ){
207: goto err_ret;
208: }
209:
210: FlushCacheM(laddr, len, mode);
211:
212: return E_OK;
213:
214: err_ret:
215: TM_DEBUG_PRINT(("_FlushMemCache ercd = %d\n", ercd));
216: return ercd;
217: }
218:
219: 220: 221:
222: LOCAL INT _ControlCache( void *addr, INT len, UINT mode )
223: {
224: ER ercd;
225:
226: if ( len <= 0 ) {
227: ercd = E_PAR;
228: goto err_ret;
229: }
230: if ( mode == 0 ) {
231: ercd = E_PAR;
232: goto err_ret;
233: }
234: ercd = ChkSpaceR(addr, len);
235: if ( ercd < E_OK ){
236: goto err_ret;
237: }
238:
239: ercd = ControlCacheM(addr, len, mode);
240: if( ercd != E_OK ){
241: goto err_ret;
242: }
243:
244: return len;
245:
246: err_ret:
247: TM_DEBUG_PRINT(("_ControlCache ercd = %d\n", ercd));
248: return ercd;
249: }
250:
251:
252:
253: 254: 255:
256: LOCAL INT SegSVCentry( void *para, W fn )
257: {
258: INT ercd;
259:
260: switch ( fn ) {
261:
262: case SEG_FLUSHMEMCACHE_FN:
263: break;
264:
265: default:
266:
267: ercd = ChkCallPLevel();
268: if ( ercd < E_OK ) {
269: goto err_ret;
270: }
271: }
272:
273: switch ( fn ) {
274: case SEG_LOCKSPACE_FN:
275: case SEG_UNLOCKSPACE_FN:
276: ercd = E_OK;
277: break;
278:
279: case SEG_CNVPHYSICALADDR_FN:
280: { SEG_CNVPHYSICALADDR_PARA *p = para;
281: ercd = _CnvPhysicalAddr(p->laddr, p->len, p->paddr); }
282: break;
283:
284: case SEG_CHKSPACE_FN:
285: { SEG_CHKSPACE_PARA *p = para;
286: ercd = _ChkSpace(p->laddr, p->len, p->mode, p->env); }
287: break;
288: case SEG_CHKSPACETSTR_FN:
289: { SEG_CHKSPACETSTR_PARA *p = para;
290: ercd = _ChkSpaceTstr(p->str, p->max, p->mode, p->env); }
291: break;
292: case SEG_CHKSPACEBSTR_FN:
293: { SEG_CHKSPACEBSTR_PARA *p = para;
294: ercd = _ChkSpaceBstr(p->str, p->max, p->mode, p->env); }
295: break;
296:
297: case SEG_MAPMEMORY_FN:
298: { SEG_MAPMEMORY_PARA *p = para;
299: ercd = _MapMemory(p->paddr, p->len, p->attr, p->laddr); }
300: break;
301: case SEG_UNMAPMEMORY_FN:
302: { SEG_UNMAPMEMORY_PARA *p = para;
303: ercd = _UnmapMemory(p->laddr); }
304: break;
305:
306: case SEG_FLUSHMEMCACHE_FN:
307: { SEG_FLUSHMEMCACHE_PARA *p = para;
308: ercd = _FlushMemCache(p->laddr, p->len, p->mode); }
309: break;
310:
311: case SEG_CHKSPACELEN_FN:
312: { SEG_CHKSPACELEN_PARA *p = para;
313: ercd = _ChkSpaceLen(p->laddr, p->len, p->mode, p->env, p->lsid); }
314: break;
315: case SEG_READMEMSPACE_FN:
316: case SEG_WRITEMEMSPACE_FN:
317: case SEG_SETMEMSPACEB_FN:
318: ercd = E_NOSPT;
319: break;
320: case SEG_MAKESPACE_FN:
321: { SEG_MAKESPACE_PARA *p = para;
322: ercd = _MakeSpace(p->laddr, p->npage, p->lsid, p->pte); }
323: break;
324: case SEG_UNMAKESPACE_FN:
325: { SEG_UNMAKESPACE_PARA *p = para;
326: ercd = _UnmakeSpace(p->laddr, p->npage, p->lsid); }
327: break;
328: case SEG_CHANGESPACE_FN:
329: { SEG_CHANGESPACE_PARA *p = para;
330: ercd = _ChangeSpace(p->laddr, p->npage, p->lsid, p->pte); }
331: break;
332:
333:
334: case SEG_CONTROLCACHE_FN:
335: { SEG_CONTROLCACHE_PARA *p = para;
336: ercd = _ControlCache(p->addr, p->len, p->mode); }
337: break;
338: case SEG_GETSPACEINFO_FN:
339: { SEG_GETSPACEINFO_PARA *p = para;
340: ercd = _GetSpaceInfo(p->addr, p->len, p->pk_spinfo); }
341: break;
342: case SEG_SETCACHEMODE_FN:
343: ercd = E_NOSPT;
344: break;
345: case SEG_SETMEMORYACCESS_FN:
346: { SEG_SETMEMORYACCESS_PARA *p = para;
347: ercd = _SetMemoryAccess(p->addr, p->len, p->mode); }
348: break;
349:
350: default:
351: ercd = E_RSFN;
352: }
353:
354: err_ret:
355: return ercd;
356: }
357:
358: 359: 360:
361: EXPORT ER init_segmgr( void )
362: {
363: ER ercd;
364:
365:
366: ercd = init_excmgr();
367: if (ercd < E_OK ) {
368: goto err_ret;
369: }
370:
371:
372: ercd = InitLogicalSpace();
373: if ( ercd < E_OK ) {
374: goto err_ret;
375: }
376:
377: err_ret:
378: return ercd;
379: }
380:
381: 382: 383:
384: EXPORT ER start_segmgr( void )
385: {
386: T_DSSY dssy;
387: ER ercd;
388:
389:
390: ercd = CreateLock(&SegLock, "Seg");
391: if ( ercd < E_OK ) {
392: goto err_ret;
393: }
394:
395:
396: ercd = start_excmgr();
397: if ( ercd < E_OK ) {
398: goto err_ret;
399: }
400:
401:
402: dssy.ssyatr = TA_NULL;
403: dssy.ssypri = SEG_PRI;
404: dssy.svchdr = (FP)SegSVCentry;
405: dssy.breakfn = NULL;
406: dssy.startupfn = NULL;
407: dssy.cleanupfn = NULL;
408: dssy.eventfn = NULL;
409: dssy.resblksz = 0;
410: ercd = tk_def_ssy(SEG_SVC, &dssy);
411: if ( ercd < E_OK ) {
412: goto err_ret;
413: }
414:
415: return E_OK;
416:
417: err_ret:
418: TM_DEBUG_PRINT(("start_segmgr ercd = %d\n", ercd));
419: return ercd;
420: }
421:
422: 423: 424:
425: EXPORT ER finish_segmgr( void )
426: {
427: ER ercd, ret = E_OK;
428:
429:
430: ercd = finish_excmgr();
431: if ( ercd < E_OK ) {
432: ret = ercd;
433: }
434:
435:
436: ercd = tk_def_ssy(SEG_SVC, NULL);
437: if ( ercd < E_OK ) {
438: ret = ercd;
439: }
440:
441:
442: DeleteLock(&SegLock);
443:
444: #ifdef DEBUG
445: if ( ret < E_OK ) {
446: TM_DEBUG_PRINT(("finish_segmgr ercd = %d\n", ret));
447: }
448: #endif
449: return ret;
450: }