1 /* ----------------------------------------------------------------------- * 2 * 3 * Copyright 2009 Pierre-Alexandre Meyer - All Rights Reserved 4 * 5 * Some part borrowed from DMI Decode: 6 * 7 * (C) 2000-2002 Alan Cox <alan (at) redhat.com> 8 * (C) 2002-2007 Jean Delvare <khali (at) linux-fr.org> 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation, Inc., 53 Temple Place Ste 330, 13 * Boston MA 02111-1307, USA; either version 2 of the License, or 14 * (at your option) any later version; incorporated herein by reference. 15 * 16 * ----------------------------------------------------------------------- */ 17 18 #include <dmi/dmi.h> 19 #include <dmi/dmi_cache.h> 20 #include <stdio.h> 21 22 /* 23 * 3.3.8 Cache Information (Type 7) 24 */ 25 26 const char *dmi_cache_mode(uint8_t code) 27 { 28 static const char *mode[] = { 29 "Write Through", /* 0x00 */ 30 "Write Back", 31 "Varies With Memory Address", 32 "Unknown" /* 0x03 */ 33 }; 34 35 return mode[code]; 36 } 37 38 const char *dmi_cache_location(uint8_t code) 39 { 40 static const char *location[4] = { 41 "Internal", /* 0x00 */ 42 "External", 43 "<OUT OF SPEC", /* 0x02 */ 44 "Unknown" /* 0x03 */ 45 }; 46 47 if (location[code] != NULL) 48 return location[code]; 49 return out_of_spec; 50 } 51 52 uint16_t dmi_cache_size(uint16_t code) 53 { 54 if (code & 0x8000) 55 return (code & 0x7FFF) << 6; /* KB */ 56 else 57 return code; /* KB */ 58 } 59 60 void dmi_cache_types(uint16_t code, const char *sep, char *array) 61 { 62 /* 3.3.8.2 */ 63 static const char *types[] = { 64 "Other", /* 0 */ 65 "Unknown", 66 "Non-burst", 67 "Burst", 68 "Pipeline Burst", 69 "Synchronous", 70 "Asynchronous" /* 6 */ 71 }; 72 73 if ((code & 0x007F) == 0) 74 strcpy(array, "None"); 75 else { 76 int i; 77 78 for (i = 0; i <= 6; i++) 79 if (code & (1 << i)) 80 sprintf(array, "%s%s", sep, types[i]); 81 } 82 } 83 84 const char *dmi_cache_ec_type(uint8_t code) 85 { 86 /* 3.3.8.3 */ 87 static const char *type[] = { 88 "Other", /* 0x01 */ 89 "Unknown", 90 "None", 91 "Parity", 92 "Single-bit ECC", 93 "Multi-bit ECC" /* 0x06 */ 94 }; 95 96 if (code >= 0x01 && code <= 0x06) 97 return type[code - 0x01]; 98 return out_of_spec; 99 } 100 101 const char *dmi_cache_type(uint8_t code) 102 { 103 /* 3.3.8.4 */ 104 static const char *type[] = { 105 "Other", /* 0x01 */ 106 "Unknown", 107 "Instruction", 108 "Data", 109 "Unified" /* 0x05 */ 110 }; 111 112 if (code >= 0x01 && code <= 0x05) 113 return type[code - 0x01]; 114 return out_of_spec; 115 } 116 117 const char *dmi_cache_associativity(uint8_t code) 118 { 119 /* 3.3.8.5 */ 120 static const char *type[] = { 121 "Other", /* 0x01 */ 122 "Unknown", 123 "Direct Mapped", 124 "2-way Set-associative", 125 "4-way Set-associative", 126 "Fully Associative", 127 "8-way Set-associative", 128 "16-way Set-associative", /* 0x08 */ 129 "12-way Set-associative", 130 "24-way Set-associative", 131 "32-way Set-associative", 132 "48-way Set-associative", 133 "64-way Set-associative" /* 0x0D */ 134 }; 135 136 if (code >= 0x01 && code <= 0x0D) 137 return type[code - 0x01]; 138 return out_of_spec; 139 } 140