tkernel_2/monitor/hwdepend/tef_em1d/src/hwinfo.c | bare source | permlink (0.03 seconds) |
1: /* 2: *---------------------------------------------------------------------- 3: * T-Kernel 2.0 Software Package 4: * 5: * Copyright 2011 by Ken Sakamura. 6: * This software is distributed under the latest version of T-License 2.x. 7: *---------------------------------------------------------------------- 8: * 9: * Released by T-Engine Forum(http://www.t-engine.org/) at 2011/05/17. 10: * Modified by TRON Forum(http://www.tron.org/) at 2015/06/01. 11: * 12: *---------------------------------------------------------------------- 13: */ 14: 15: /* 16: * hwinfo.c 17: * 18: * hardware configuration information 19: */ 20: 21: #include "hwdepend.h" 22: 23: /* ------------------------------------------------------------------------ */ 24: /* 25: * memory region definition 26: */ 27: 28: /* 29: * obtaining memory region information 30: * no = 1 - (and up) 31: * 'no'-th information in the region specified by the attr is returned. 32: * if attr = 0, no matter what the attribute is, 'no'-th information is returned unconditionally. 33: * If there was no such information, return NULL. 34: */ 35: EXPORT MEMSEG* MemArea( UW attr, W no ) 36: { 37: MEMSEG *mp; 38: W i; 39: 40: if ( attr == 0 ) { 41: i = no - 1; 42: return ( i >= 0 && i < N_MemSeg )? &MemSeg[i]: NULL; 43: } 44: 45: for ( i = 0; i < N_MemSeg; ++i ) { 46: mp = &MemSeg[i]; 47: if ( (mp->attr & attr) != 0 ) { 48: if ( --no <= 0 ) return mp; 49: } 50: } 51: 52: return NULL; 53: } 54: 55: /* 56: * obtaining memory region information (specify address) 57: * within the region specified by `attr', return the information that surrounds the position specified by `addr'. 58: * 59: * if no such information is found, return NULL. 60: */ 61: EXPORT MEMSEG* AddrMatchMemArea( UW addr, UW attr ) 62: { 63: MEMSEG *mp; 64: W i; 65: 66: for ( i = 0; i < N_MemSeg; ++i ) { 67: mp = &MemSeg[i]; 68: if ( (mp->attr & attr) == 0 ) continue; 69: 70: if ( addr >= mp->top && addr <= mp->end-1 ) return mp; 71: } 72: 73: return NULL; 74: } 75: 76: /* 77: * Decide whether two memory regions are included in another. 78: * if the region, from `top' to `end', is completely included in the region specified by `attr', 79: * TRUE 80: * the location of end is NOT included in the region (end - top) is the region size 81: * end = 0x00000000, by the way, means 0x100000000. 82: */ 83: EXPORT BOOL inMemArea( UW top, UW end, UW attr ) 84: { 85: const MEMSEG *mp; 86: W i; 87: 88: for ( i = 0; i < N_MemSeg; ++i ) { 89: mp = &MemSeg[i]; 90: if ( (mp->attr & attr) == 0 ) continue; 91: 92: if ( top >= mp->top && end-1 <= mp->end-1 ) return TRUE; 93: } 94: return FALSE; 95: } 96: 97: /* 98: * Decide whether two memory regions overlap with each other 99: * if the area, from top to end, is included even partially in the region specified by `attr' - 'end', 100: * it is TRUE 101: * the location of end is NOT included in the region (end - top) is the region size 102: * end = 0x00000000, by the way, means 0x100000000. 103: */ 104: EXPORT BOOL isOverlapMemArea( UW top, UW end, UW attr ) 105: { 106: const MEMSEG *mp; 107: W i; 108: 109: for ( i = 0; i < N_MemSeg; ++i ) { 110: mp = &MemSeg[i]; 111: if ( (mp->attr & attr) == 0 ) continue; 112: 113: if ( top <= mp->end-1 && end-1 >= mp->top ) return TRUE; 114: } 115: return FALSE; 116: } 117: 118: /* ------------------------------------------------------------------------ */ 119: /* 120: * boot device following the standard boot order 121: * return the device name that is the 'no'-th device in the standard boot order. 122: * 123: * if no such device name exists (when 'no' is given as a value larger or equal to the last number), it is NULL. 124: */ 125: EXPORT const UB* bootDevice( W no ) 126: { 127: if ( no < 0 || no >= N_ConfigDisk ) return NULL; 128: 129: return ConfigDisk[no].name; 130: } 131: 132: /* 133: * list of disk drives 134: * returns the disk drive device name, indicated by 'no' ( 0 - : a consecutive number ) 135: * if no such device name exists (when 'no' is given as a value larger or equal to the last number), it is NULL. 136: * if attr is not NULL, disk driver attribute returns in `attr' ) 137: */ 138: EXPORT const UB* diskList( W no, UW *attr ) 139: { 140: if ( no < 0 || no >= N_ConfigDisk ) return NULL; 141: 142: if ( attr != NULL ) *attr = ConfigDisk[no].attr; 143: 144: return ConfigDisk[no].name; 145: } 146: 147: /* ------------------------------------------------------------------------ */