intel_cacheinfo.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205
  1. /*
  2. * Routines to indentify caches on Intel CPU.
  3. *
  4. * Changes:
  5. * Venkatesh Pallipadi : Adding cache identification through cpuid(4)
  6. * Ashok Raj <ashok.raj@intel.com>: Work with CPU hotplug infrastructure.
  7. * Andi Kleen / Andreas Herrmann : CPUID4 emulation on AMD.
  8. */
  9. #include <linux/init.h>
  10. #include <linux/slab.h>
  11. #include <linux/device.h>
  12. #include <linux/compiler.h>
  13. #include <linux/cpu.h>
  14. #include <linux/sched.h>
  15. #include <linux/pci.h>
  16. #include <asm/processor.h>
  17. #include <linux/smp.h>
  18. #include <asm/k8.h>
  19. #include <asm/smp.h>
  20. #define LVL_1_INST 1
  21. #define LVL_1_DATA 2
  22. #define LVL_2 3
  23. #define LVL_3 4
  24. #define LVL_TRACE 5
  25. struct _cache_table {
  26. unsigned char descriptor;
  27. char cache_type;
  28. short size;
  29. };
  30. #define MB(x) ((x) * 1024)
  31. /* All the cache descriptor types we care about (no TLB or
  32. trace cache entries) */
  33. static const struct _cache_table __cpuinitconst cache_table[] =
  34. {
  35. { 0x06, LVL_1_INST, 8 }, /* 4-way set assoc, 32 byte line size */
  36. { 0x08, LVL_1_INST, 16 }, /* 4-way set assoc, 32 byte line size */
  37. { 0x09, LVL_1_INST, 32 }, /* 4-way set assoc, 64 byte line size */
  38. { 0x0a, LVL_1_DATA, 8 }, /* 2 way set assoc, 32 byte line size */
  39. { 0x0c, LVL_1_DATA, 16 }, /* 4-way set assoc, 32 byte line size */
  40. { 0x0d, LVL_1_DATA, 16 }, /* 4-way set assoc, 64 byte line size */
  41. { 0x21, LVL_2, 256 }, /* 8-way set assoc, 64 byte line size */
  42. { 0x22, LVL_3, 512 }, /* 4-way set assoc, sectored cache, 64 byte line size */
  43. { 0x23, LVL_3, MB(1) }, /* 8-way set assoc, sectored cache, 64 byte line size */
  44. { 0x25, LVL_3, MB(2) }, /* 8-way set assoc, sectored cache, 64 byte line size */
  45. { 0x29, LVL_3, MB(4) }, /* 8-way set assoc, sectored cache, 64 byte line size */
  46. { 0x2c, LVL_1_DATA, 32 }, /* 8-way set assoc, 64 byte line size */
  47. { 0x30, LVL_1_INST, 32 }, /* 8-way set assoc, 64 byte line size */
  48. { 0x39, LVL_2, 128 }, /* 4-way set assoc, sectored cache, 64 byte line size */
  49. { 0x3a, LVL_2, 192 }, /* 6-way set assoc, sectored cache, 64 byte line size */
  50. { 0x3b, LVL_2, 128 }, /* 2-way set assoc, sectored cache, 64 byte line size */
  51. { 0x3c, LVL_2, 256 }, /* 4-way set assoc, sectored cache, 64 byte line size */
  52. { 0x3d, LVL_2, 384 }, /* 6-way set assoc, sectored cache, 64 byte line size */
  53. { 0x3e, LVL_2, 512 }, /* 4-way set assoc, sectored cache, 64 byte line size */
  54. { 0x3f, LVL_2, 256 }, /* 2-way set assoc, 64 byte line size */
  55. { 0x41, LVL_2, 128 }, /* 4-way set assoc, 32 byte line size */
  56. { 0x42, LVL_2, 256 }, /* 4-way set assoc, 32 byte line size */
  57. { 0x43, LVL_2, 512 }, /* 4-way set assoc, 32 byte line size */
  58. { 0x44, LVL_2, MB(1) }, /* 4-way set assoc, 32 byte line size */
  59. { 0x45, LVL_2, MB(2) }, /* 4-way set assoc, 32 byte line size */
  60. { 0x46, LVL_3, MB(4) }, /* 4-way set assoc, 64 byte line size */
  61. { 0x47, LVL_3, MB(8) }, /* 8-way set assoc, 64 byte line size */
  62. { 0x49, LVL_3, MB(4) }, /* 16-way set assoc, 64 byte line size */
  63. { 0x4a, LVL_3, MB(6) }, /* 12-way set assoc, 64 byte line size */
  64. { 0x4b, LVL_3, MB(8) }, /* 16-way set assoc, 64 byte line size */
  65. { 0x4c, LVL_3, MB(12) }, /* 12-way set assoc, 64 byte line size */
  66. { 0x4d, LVL_3, MB(16) }, /* 16-way set assoc, 64 byte line size */
  67. { 0x4e, LVL_2, MB(6) }, /* 24-way set assoc, 64 byte line size */
  68. { 0x60, LVL_1_DATA, 16 }, /* 8-way set assoc, sectored cache, 64 byte line size */
  69. { 0x66, LVL_1_DATA, 8 }, /* 4-way set assoc, sectored cache, 64 byte line size */
  70. { 0x67, LVL_1_DATA, 16 }, /* 4-way set assoc, sectored cache, 64 byte line size */
  71. { 0x68, LVL_1_DATA, 32 }, /* 4-way set assoc, sectored cache, 64 byte line size */
  72. { 0x70, LVL_TRACE, 12 }, /* 8-way set assoc */
  73. { 0x71, LVL_TRACE, 16 }, /* 8-way set assoc */
  74. { 0x72, LVL_TRACE, 32 }, /* 8-way set assoc */
  75. { 0x73, LVL_TRACE, 64 }, /* 8-way set assoc */
  76. { 0x78, LVL_2, MB(1) }, /* 4-way set assoc, 64 byte line size */
  77. { 0x79, LVL_2, 128 }, /* 8-way set assoc, sectored cache, 64 byte line size */
  78. { 0x7a, LVL_2, 256 }, /* 8-way set assoc, sectored cache, 64 byte line size */
  79. { 0x7b, LVL_2, 512 }, /* 8-way set assoc, sectored cache, 64 byte line size */
  80. { 0x7c, LVL_2, MB(1) }, /* 8-way set assoc, sectored cache, 64 byte line size */
  81. { 0x7d, LVL_2, MB(2) }, /* 8-way set assoc, 64 byte line size */
  82. { 0x7f, LVL_2, 512 }, /* 2-way set assoc, 64 byte line size */
  83. { 0x82, LVL_2, 256 }, /* 8-way set assoc, 32 byte line size */
  84. { 0x83, LVL_2, 512 }, /* 8-way set assoc, 32 byte line size */
  85. { 0x84, LVL_2, MB(1) }, /* 8-way set assoc, 32 byte line size */
  86. { 0x85, LVL_2, MB(2) }, /* 8-way set assoc, 32 byte line size */
  87. { 0x86, LVL_2, 512 }, /* 4-way set assoc, 64 byte line size */
  88. { 0x87, LVL_2, MB(1) }, /* 8-way set assoc, 64 byte line size */
  89. { 0xd0, LVL_3, 512 }, /* 4-way set assoc, 64 byte line size */
  90. { 0xd1, LVL_3, MB(1) }, /* 4-way set assoc, 64 byte line size */
  91. { 0xd2, LVL_3, MB(2) }, /* 4-way set assoc, 64 byte line size */
  92. { 0xd6, LVL_3, MB(1) }, /* 8-way set assoc, 64 byte line size */
  93. { 0xd7, LVL_3, MB(2) }, /* 8-way set assoc, 64 byte line size */
  94. { 0xd8, LVL_3, MB(4) }, /* 12-way set assoc, 64 byte line size */
  95. { 0xdc, LVL_3, MB(2) }, /* 12-way set assoc, 64 byte line size */
  96. { 0xdd, LVL_3, MB(4) }, /* 12-way set assoc, 64 byte line size */
  97. { 0xde, LVL_3, MB(8) }, /* 12-way set assoc, 64 byte line size */
  98. { 0xe2, LVL_3, MB(2) }, /* 16-way set assoc, 64 byte line size */
  99. { 0xe3, LVL_3, MB(4) }, /* 16-way set assoc, 64 byte line size */
  100. { 0xe4, LVL_3, MB(8) }, /* 16-way set assoc, 64 byte line size */
  101. { 0xea, LVL_3, MB(12) }, /* 24-way set assoc, 64 byte line size */
  102. { 0xeb, LVL_3, MB(18) }, /* 24-way set assoc, 64 byte line size */
  103. { 0xec, LVL_3, MB(24) }, /* 24-way set assoc, 64 byte line size */
  104. { 0x00, 0, 0}
  105. };
  106. enum _cache_type {
  107. CACHE_TYPE_NULL = 0,
  108. CACHE_TYPE_DATA = 1,
  109. CACHE_TYPE_INST = 2,
  110. CACHE_TYPE_UNIFIED = 3
  111. };
  112. union _cpuid4_leaf_eax {
  113. struct {
  114. enum _cache_type type:5;
  115. unsigned int level:3;
  116. unsigned int is_self_initializing:1;
  117. unsigned int is_fully_associative:1;
  118. unsigned int reserved:4;
  119. unsigned int num_threads_sharing:12;
  120. unsigned int num_cores_on_die:6;
  121. } split;
  122. u32 full;
  123. };
  124. union _cpuid4_leaf_ebx {
  125. struct {
  126. unsigned int coherency_line_size:12;
  127. unsigned int physical_line_partition:10;
  128. unsigned int ways_of_associativity:10;
  129. } split;
  130. u32 full;
  131. };
  132. union _cpuid4_leaf_ecx {
  133. struct {
  134. unsigned int number_of_sets:32;
  135. } split;
  136. u32 full;
  137. };
  138. struct amd_l3_cache {
  139. struct pci_dev *dev;
  140. bool can_disable;
  141. unsigned indices;
  142. u8 subcaches[4];
  143. };
  144. struct _cpuid4_info {
  145. union _cpuid4_leaf_eax eax;
  146. union _cpuid4_leaf_ebx ebx;
  147. union _cpuid4_leaf_ecx ecx;
  148. unsigned long size;
  149. struct amd_l3_cache *l3;
  150. DECLARE_BITMAP(shared_cpu_map, NR_CPUS);
  151. };
  152. /* subset of above _cpuid4_info w/o shared_cpu_map */
  153. struct _cpuid4_info_regs {
  154. union _cpuid4_leaf_eax eax;
  155. union _cpuid4_leaf_ebx ebx;
  156. union _cpuid4_leaf_ecx ecx;
  157. unsigned long size;
  158. struct amd_l3_cache *l3;
  159. };
  160. unsigned short num_cache_leaves;
  161. /* AMD doesn't have CPUID4. Emulate it here to report the same
  162. information to the user. This makes some assumptions about the machine:
  163. L2 not shared, no SMT etc. that is currently true on AMD CPUs.
  164. In theory the TLBs could be reported as fake type (they are in "dummy").
  165. Maybe later */
  166. union l1_cache {
  167. struct {
  168. unsigned line_size:8;
  169. unsigned lines_per_tag:8;
  170. unsigned assoc:8;
  171. unsigned size_in_kb:8;
  172. };
  173. unsigned val;
  174. };
  175. union l2_cache {
  176. struct {
  177. unsigned line_size:8;
  178. unsigned lines_per_tag:4;
  179. unsigned assoc:4;
  180. unsigned size_in_kb:16;
  181. };
  182. unsigned val;
  183. };
  184. union l3_cache {
  185. struct {
  186. unsigned line_size:8;
  187. unsigned lines_per_tag:4;
  188. unsigned assoc:4;
  189. unsigned res:2;
  190. unsigned size_encoded:14;
  191. };
  192. unsigned val;
  193. };
  194. static const unsigned short __cpuinitconst assocs[] = {
  195. [1] = 1,
  196. [2] = 2,
  197. [4] = 4,
  198. [6] = 8,
  199. [8] = 16,
  200. [0xa] = 32,
  201. [0xb] = 48,
  202. [0xc] = 64,
  203. [0xd] = 96,
  204. [0xe] = 128,
  205. [0xf] = 0xffff /* fully associative - no way to show this currently */
  206. };
  207. static const unsigned char __cpuinitconst levels[] = { 1, 1, 2, 3 };
  208. static const unsigned char __cpuinitconst types[] = { 1, 2, 3, 3 };
  209. static void __cpuinit
  210. amd_cpuid4(int leaf, union _cpuid4_leaf_eax *eax,
  211. union _cpuid4_leaf_ebx *ebx,
  212. union _cpuid4_leaf_ecx *ecx)
  213. {
  214. unsigned dummy;
  215. unsigned line_size, lines_per_tag, assoc, size_in_kb;
  216. union l1_cache l1i, l1d;
  217. union l2_cache l2;
  218. union l3_cache l3;
  219. union l1_cache *l1 = &l1d;
  220. eax->full = 0;
  221. ebx->full = 0;
  222. ecx->full = 0;
  223. cpuid(0x80000005, &dummy, &dummy, &l1d.val, &l1i.val);
  224. cpuid(0x80000006, &dummy, &dummy, &l2.val, &l3.val);
  225. switch (leaf) {
  226. case 1:
  227. l1 = &l1i;
  228. case 0:
  229. if (!l1->val)
  230. return;
  231. assoc = assocs[l1->assoc];
  232. line_size = l1->line_size;
  233. lines_per_tag = l1->lines_per_tag;
  234. size_in_kb = l1->size_in_kb;
  235. break;
  236. case 2:
  237. if (!l2.val)
  238. return;
  239. assoc = assocs[l2.assoc];
  240. line_size = l2.line_size;
  241. lines_per_tag = l2.lines_per_tag;
  242. /* cpu_data has errata corrections for K7 applied */
  243. size_in_kb = current_cpu_data.x86_cache_size;
  244. break;
  245. case 3:
  246. if (!l3.val)
  247. return;
  248. assoc = assocs[l3.assoc];
  249. line_size = l3.line_size;
  250. lines_per_tag = l3.lines_per_tag;
  251. size_in_kb = l3.size_encoded * 512;
  252. if (boot_cpu_has(X86_FEATURE_AMD_DCM)) {
  253. size_in_kb = size_in_kb >> 1;
  254. assoc = assoc >> 1;
  255. }
  256. break;
  257. default:
  258. return;
  259. }
  260. eax->split.is_self_initializing = 1;
  261. eax->split.type = types[leaf];
  262. eax->split.level = levels[leaf];
  263. eax->split.num_threads_sharing = 0;
  264. eax->split.num_cores_on_die = current_cpu_data.x86_max_cores - 1;
  265. if (assoc == 0xffff)
  266. eax->split.is_fully_associative = 1;
  267. ebx->split.coherency_line_size = line_size - 1;
  268. ebx->split.ways_of_associativity = assoc - 1;
  269. ebx->split.physical_line_partition = lines_per_tag - 1;
  270. ecx->split.number_of_sets = (size_in_kb * 1024) / line_size /
  271. (ebx->split.ways_of_associativity + 1) - 1;
  272. }
  273. struct _cache_attr {
  274. struct attribute attr;
  275. ssize_t (*show)(struct _cpuid4_info *, char *);
  276. ssize_t (*store)(struct _cpuid4_info *, const char *, size_t count);
  277. };
  278. #ifdef CONFIG_CPU_SUP_AMD
  279. /*
  280. * L3 cache descriptors
  281. */
  282. static struct amd_l3_cache **__cpuinitdata l3_caches;
  283. static void __cpuinit amd_calc_l3_indices(struct amd_l3_cache *l3)
  284. {
  285. unsigned int sc0, sc1, sc2, sc3;
  286. u32 val = 0;
  287. pci_read_config_dword(l3->dev, 0x1C4, &val);
  288. /* calculate subcache sizes */
  289. l3->subcaches[0] = sc0 = !(val & BIT(0));
  290. l3->subcaches[1] = sc1 = !(val & BIT(4));
  291. l3->subcaches[2] = sc2 = !(val & BIT(8)) + !(val & BIT(9));
  292. l3->subcaches[3] = sc3 = !(val & BIT(12)) + !(val & BIT(13));
  293. l3->indices = (max(max(max(sc0, sc1), sc2), sc3) << 10) - 1;
  294. }
  295. static struct amd_l3_cache * __cpuinit amd_init_l3_cache(int node)
  296. {
  297. struct amd_l3_cache *l3;
  298. struct pci_dev *dev = node_to_k8_nb_misc(node);
  299. l3 = kzalloc(sizeof(struct amd_l3_cache), GFP_ATOMIC);
  300. if (!l3) {
  301. printk(KERN_WARNING "Error allocating L3 struct\n");
  302. return NULL;
  303. }
  304. l3->dev = dev;
  305. amd_calc_l3_indices(l3);
  306. return l3;
  307. }
  308. static void __cpuinit amd_check_l3_disable(struct _cpuid4_info_regs *this_leaf,
  309. int index)
  310. {
  311. int node;
  312. if (boot_cpu_data.x86 != 0x10)
  313. return;
  314. if (index < 3)
  315. return;
  316. /* see errata #382 and #388 */
  317. if (boot_cpu_data.x86_model < 0x8)
  318. return;
  319. if ((boot_cpu_data.x86_model == 0x8 ||
  320. boot_cpu_data.x86_model == 0x9)
  321. &&
  322. boot_cpu_data.x86_mask < 0x1)
  323. return;
  324. /* not in virtualized environments */
  325. if (num_k8_northbridges == 0)
  326. return;
  327. /*
  328. * Strictly speaking, the amount in @size below is leaked since it is
  329. * never freed but this is done only on shutdown so it doesn't matter.
  330. */
  331. if (!l3_caches) {
  332. int size = num_k8_northbridges * sizeof(struct amd_l3_cache *);
  333. l3_caches = kzalloc(size, GFP_ATOMIC);
  334. if (!l3_caches)
  335. return;
  336. }
  337. node = amd_get_nb_id(smp_processor_id());
  338. if (!l3_caches[node]) {
  339. l3_caches[node] = amd_init_l3_cache(node);
  340. l3_caches[node]->can_disable = true;
  341. }
  342. WARN_ON(!l3_caches[node]);
  343. this_leaf->l3 = l3_caches[node];
  344. }
  345. /*
  346. * check whether a slot used for disabling an L3 index is occupied.
  347. * @l3: L3 cache descriptor
  348. * @slot: slot number (0..1)
  349. *
  350. * @returns: the disabled index if used or negative value if slot free.
  351. */
  352. int amd_get_l3_disable_slot(struct amd_l3_cache *l3, unsigned slot)
  353. {
  354. unsigned int reg = 0;
  355. pci_read_config_dword(l3->dev, 0x1BC + slot * 4, &reg);
  356. /* check whether this slot is activated already */
  357. if (reg & (3UL << 30))
  358. return reg & 0xfff;
  359. return -1;
  360. }
  361. static ssize_t show_cache_disable(struct _cpuid4_info *this_leaf, char *buf,
  362. unsigned int slot)
  363. {
  364. int index;
  365. if (!this_leaf->l3 || !this_leaf->l3->can_disable)
  366. return -EINVAL;
  367. index = amd_get_l3_disable_slot(this_leaf->l3, slot);
  368. if (index >= 0)
  369. return sprintf(buf, "%d\n", index);
  370. return sprintf(buf, "FREE\n");
  371. }
  372. #define SHOW_CACHE_DISABLE(slot) \
  373. static ssize_t \
  374. show_cache_disable_##slot(struct _cpuid4_info *this_leaf, char *buf) \
  375. { \
  376. return show_cache_disable(this_leaf, buf, slot); \
  377. }
  378. SHOW_CACHE_DISABLE(0)
  379. SHOW_CACHE_DISABLE(1)
  380. static void amd_l3_disable_index(struct amd_l3_cache *l3, int cpu,
  381. unsigned slot, unsigned long idx)
  382. {
  383. int i;
  384. idx |= BIT(30);
  385. /*
  386. * disable index in all 4 subcaches
  387. */
  388. for (i = 0; i < 4; i++) {
  389. u32 reg = idx | (i << 20);
  390. if (!l3->subcaches[i])
  391. continue;
  392. pci_write_config_dword(l3->dev, 0x1BC + slot * 4, reg);
  393. /*
  394. * We need to WBINVD on a core on the node containing the L3
  395. * cache which indices we disable therefore a simple wbinvd()
  396. * is not sufficient.
  397. */
  398. wbinvd_on_cpu(cpu);
  399. reg |= BIT(31);
  400. pci_write_config_dword(l3->dev, 0x1BC + slot * 4, reg);
  401. }
  402. }
  403. /*
  404. * disable a L3 cache index by using a disable-slot
  405. *
  406. * @l3: L3 cache descriptor
  407. * @cpu: A CPU on the node containing the L3 cache
  408. * @slot: slot number (0..1)
  409. * @index: index to disable
  410. *
  411. * @return: 0 on success, error status on failure
  412. */
  413. int amd_set_l3_disable_slot(struct amd_l3_cache *l3, int cpu, unsigned slot,
  414. unsigned long index)
  415. {
  416. int ret = 0;
  417. #define SUBCACHE_MASK (3UL << 20)
  418. #define SUBCACHE_INDEX 0xfff
  419. /*
  420. * check whether this slot is already used or
  421. * the index is already disabled
  422. */
  423. ret = amd_get_l3_disable_slot(l3, slot);
  424. if (ret >= 0)
  425. return -EINVAL;
  426. /*
  427. * check whether the other slot has disabled the
  428. * same index already
  429. */
  430. if (index == amd_get_l3_disable_slot(l3, !slot))
  431. return -EINVAL;
  432. /* do not allow writes outside of allowed bits */
  433. if ((index & ~(SUBCACHE_MASK | SUBCACHE_INDEX)) ||
  434. ((index & SUBCACHE_INDEX) > l3->indices))
  435. return -EINVAL;
  436. amd_l3_disable_index(l3, cpu, slot, index);
  437. return 0;
  438. }
  439. static ssize_t store_cache_disable(struct _cpuid4_info *this_leaf,
  440. const char *buf, size_t count,
  441. unsigned int slot)
  442. {
  443. unsigned long val = 0;
  444. int cpu, err = 0;
  445. if (!capable(CAP_SYS_ADMIN))
  446. return -EPERM;
  447. if (!this_leaf->l3 || !this_leaf->l3->can_disable)
  448. return -EINVAL;
  449. cpu = cpumask_first(to_cpumask(this_leaf->shared_cpu_map));
  450. if (strict_strtoul(buf, 10, &val) < 0)
  451. return -EINVAL;
  452. err = amd_set_l3_disable_slot(this_leaf->l3, cpu, slot, val);
  453. if (err) {
  454. if (err == -EEXIST)
  455. printk(KERN_WARNING "L3 disable slot %d in use!\n",
  456. slot);
  457. return err;
  458. }
  459. return count;
  460. }
  461. #define STORE_CACHE_DISABLE(slot) \
  462. static ssize_t \
  463. store_cache_disable_##slot(struct _cpuid4_info *this_leaf, \
  464. const char *buf, size_t count) \
  465. { \
  466. return store_cache_disable(this_leaf, buf, count, slot); \
  467. }
  468. STORE_CACHE_DISABLE(0)
  469. STORE_CACHE_DISABLE(1)
  470. static struct _cache_attr cache_disable_0 = __ATTR(cache_disable_0, 0644,
  471. show_cache_disable_0, store_cache_disable_0);
  472. static struct _cache_attr cache_disable_1 = __ATTR(cache_disable_1, 0644,
  473. show_cache_disable_1, store_cache_disable_1);
  474. #else /* CONFIG_CPU_SUP_AMD */
  475. static void __cpuinit
  476. amd_check_l3_disable(struct _cpuid4_info_regs *this_leaf, int index)
  477. {
  478. };
  479. #endif /* CONFIG_CPU_SUP_AMD */
  480. static int
  481. __cpuinit cpuid4_cache_lookup_regs(int index,
  482. struct _cpuid4_info_regs *this_leaf)
  483. {
  484. union _cpuid4_leaf_eax eax;
  485. union _cpuid4_leaf_ebx ebx;
  486. union _cpuid4_leaf_ecx ecx;
  487. unsigned edx;
  488. if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) {
  489. amd_cpuid4(index, &eax, &ebx, &ecx);
  490. amd_check_l3_disable(this_leaf, index);
  491. } else {
  492. cpuid_count(4, index, &eax.full, &ebx.full, &ecx.full, &edx);
  493. }
  494. if (eax.split.type == CACHE_TYPE_NULL)
  495. return -EIO; /* better error ? */
  496. this_leaf->eax = eax;
  497. this_leaf->ebx = ebx;
  498. this_leaf->ecx = ecx;
  499. this_leaf->size = (ecx.split.number_of_sets + 1) *
  500. (ebx.split.coherency_line_size + 1) *
  501. (ebx.split.physical_line_partition + 1) *
  502. (ebx.split.ways_of_associativity + 1);
  503. return 0;
  504. }
  505. static int __cpuinit find_num_cache_leaves(void)
  506. {
  507. unsigned int eax, ebx, ecx, edx;
  508. union _cpuid4_leaf_eax cache_eax;
  509. int i = -1;
  510. do {
  511. ++i;
  512. /* Do cpuid(4) loop to find out num_cache_leaves */
  513. cpuid_count(4, i, &eax, &ebx, &ecx, &edx);
  514. cache_eax.full = eax;
  515. } while (cache_eax.split.type != CACHE_TYPE_NULL);
  516. return i;
  517. }
  518. unsigned int __cpuinit init_intel_cacheinfo(struct cpuinfo_x86 *c)
  519. {
  520. /* Cache sizes */
  521. unsigned int trace = 0, l1i = 0, l1d = 0, l2 = 0, l3 = 0;
  522. unsigned int new_l1d = 0, new_l1i = 0; /* Cache sizes from cpuid(4) */
  523. unsigned int new_l2 = 0, new_l3 = 0, i; /* Cache sizes from cpuid(4) */
  524. unsigned int l2_id = 0, l3_id = 0, num_threads_sharing, index_msb;
  525. #ifdef CONFIG_X86_HT
  526. unsigned int cpu = c->cpu_index;
  527. #endif
  528. if (c->cpuid_level > 3) {
  529. static int is_initialized;
  530. if (is_initialized == 0) {
  531. /* Init num_cache_leaves from boot CPU */
  532. num_cache_leaves = find_num_cache_leaves();
  533. is_initialized++;
  534. }
  535. /*
  536. * Whenever possible use cpuid(4), deterministic cache
  537. * parameters cpuid leaf to find the cache details
  538. */
  539. for (i = 0; i < num_cache_leaves; i++) {
  540. struct _cpuid4_info_regs this_leaf;
  541. int retval;
  542. retval = cpuid4_cache_lookup_regs(i, &this_leaf);
  543. if (retval >= 0) {
  544. switch (this_leaf.eax.split.level) {
  545. case 1:
  546. if (this_leaf.eax.split.type ==
  547. CACHE_TYPE_DATA)
  548. new_l1d = this_leaf.size/1024;
  549. else if (this_leaf.eax.split.type ==
  550. CACHE_TYPE_INST)
  551. new_l1i = this_leaf.size/1024;
  552. break;
  553. case 2:
  554. new_l2 = this_leaf.size/1024;
  555. num_threads_sharing = 1 + this_leaf.eax.split.num_threads_sharing;
  556. index_msb = get_count_order(num_threads_sharing);
  557. l2_id = c->apicid >> index_msb;
  558. break;
  559. case 3:
  560. new_l3 = this_leaf.size/1024;
  561. num_threads_sharing = 1 + this_leaf.eax.split.num_threads_sharing;
  562. index_msb = get_count_order(
  563. num_threads_sharing);
  564. l3_id = c->apicid >> index_msb;
  565. break;
  566. default:
  567. break;
  568. }
  569. }
  570. }
  571. }
  572. /*
  573. * Don't use cpuid2 if cpuid4 is supported. For P4, we use cpuid2 for
  574. * trace cache
  575. */
  576. if ((num_cache_leaves == 0 || c->x86 == 15) && c->cpuid_level > 1) {
  577. /* supports eax=2 call */
  578. int j, n;
  579. unsigned int regs[4];
  580. unsigned char *dp = (unsigned char *)regs;
  581. int only_trace = 0;
  582. if (num_cache_leaves != 0 && c->x86 == 15)
  583. only_trace = 1;
  584. /* Number of times to iterate */
  585. n = cpuid_eax(2) & 0xFF;
  586. for (i = 0 ; i < n ; i++) {
  587. cpuid(2, &regs[0], &regs[1], &regs[2], &regs[3]);
  588. /* If bit 31 is set, this is an unknown format */
  589. for (j = 0 ; j < 3 ; j++)
  590. if (regs[j] & (1 << 31))
  591. regs[j] = 0;
  592. /* Byte 0 is level count, not a descriptor */
  593. for (j = 1 ; j < 16 ; j++) {
  594. unsigned char des = dp[j];
  595. unsigned char k = 0;
  596. /* look up this descriptor in the table */
  597. while (cache_table[k].descriptor != 0) {
  598. if (cache_table[k].descriptor == des) {
  599. if (only_trace && cache_table[k].cache_type != LVL_TRACE)
  600. break;
  601. switch (cache_table[k].cache_type) {
  602. case LVL_1_INST:
  603. l1i += cache_table[k].size;
  604. break;
  605. case LVL_1_DATA:
  606. l1d += cache_table[k].size;
  607. break;
  608. case LVL_2:
  609. l2 += cache_table[k].size;
  610. break;
  611. case LVL_3:
  612. l3 += cache_table[k].size;
  613. break;
  614. case LVL_TRACE:
  615. trace += cache_table[k].size;
  616. break;
  617. }
  618. break;
  619. }
  620. k++;
  621. }
  622. }
  623. }
  624. }
  625. if (new_l1d)
  626. l1d = new_l1d;
  627. if (new_l1i)
  628. l1i = new_l1i;
  629. if (new_l2) {
  630. l2 = new_l2;
  631. #ifdef CONFIG_X86_HT
  632. per_cpu(cpu_llc_id, cpu) = l2_id;
  633. #endif
  634. }
  635. if (new_l3) {
  636. l3 = new_l3;
  637. #ifdef CONFIG_X86_HT
  638. per_cpu(cpu_llc_id, cpu) = l3_id;
  639. #endif
  640. }
  641. c->x86_cache_size = l3 ? l3 : (l2 ? l2 : (l1i+l1d));
  642. return l2;
  643. }
  644. #ifdef CONFIG_SYSFS
  645. /* pointer to _cpuid4_info array (for each cache leaf) */
  646. static DEFINE_PER_CPU(struct _cpuid4_info *, ici_cpuid4_info);
  647. #define CPUID4_INFO_IDX(x, y) (&((per_cpu(ici_cpuid4_info, x))[y]))
  648. #ifdef CONFIG_SMP
  649. static void __cpuinit cache_shared_cpu_map_setup(unsigned int cpu, int index)
  650. {
  651. struct _cpuid4_info *this_leaf, *sibling_leaf;
  652. unsigned long num_threads_sharing;
  653. int index_msb, i, sibling;
  654. struct cpuinfo_x86 *c = &cpu_data(cpu);
  655. if ((index == 3) && (c->x86_vendor == X86_VENDOR_AMD)) {
  656. for_each_cpu(i, c->llc_shared_map) {
  657. if (!per_cpu(ici_cpuid4_info, i))
  658. continue;
  659. this_leaf = CPUID4_INFO_IDX(i, index);
  660. for_each_cpu(sibling, c->llc_shared_map) {
  661. if (!cpu_online(sibling))
  662. continue;
  663. set_bit(sibling, this_leaf->shared_cpu_map);
  664. }
  665. }
  666. return;
  667. }
  668. this_leaf = CPUID4_INFO_IDX(cpu, index);
  669. num_threads_sharing = 1 + this_leaf->eax.split.num_threads_sharing;
  670. if (num_threads_sharing == 1)
  671. cpumask_set_cpu(cpu, to_cpumask(this_leaf->shared_cpu_map));
  672. else {
  673. index_msb = get_count_order(num_threads_sharing);
  674. for_each_online_cpu(i) {
  675. if (cpu_data(i).apicid >> index_msb ==
  676. c->apicid >> index_msb) {
  677. cpumask_set_cpu(i,
  678. to_cpumask(this_leaf->shared_cpu_map));
  679. if (i != cpu && per_cpu(ici_cpuid4_info, i)) {
  680. sibling_leaf =
  681. CPUID4_INFO_IDX(i, index);
  682. cpumask_set_cpu(cpu, to_cpumask(
  683. sibling_leaf->shared_cpu_map));
  684. }
  685. }
  686. }
  687. }
  688. }
  689. static void __cpuinit cache_remove_shared_cpu_map(unsigned int cpu, int index)
  690. {
  691. struct _cpuid4_info *this_leaf, *sibling_leaf;
  692. int sibling;
  693. this_leaf = CPUID4_INFO_IDX(cpu, index);
  694. for_each_cpu(sibling, to_cpumask(this_leaf->shared_cpu_map)) {
  695. sibling_leaf = CPUID4_INFO_IDX(sibling, index);
  696. cpumask_clear_cpu(cpu,
  697. to_cpumask(sibling_leaf->shared_cpu_map));
  698. }
  699. }
  700. #else
  701. static void __cpuinit cache_shared_cpu_map_setup(unsigned int cpu, int index)
  702. {
  703. }
  704. static void __cpuinit cache_remove_shared_cpu_map(unsigned int cpu, int index)
  705. {
  706. }
  707. #endif
  708. static void __cpuinit free_cache_attributes(unsigned int cpu)
  709. {
  710. int i;
  711. for (i = 0; i < num_cache_leaves; i++)
  712. cache_remove_shared_cpu_map(cpu, i);
  713. kfree(per_cpu(ici_cpuid4_info, cpu)->l3);
  714. kfree(per_cpu(ici_cpuid4_info, cpu));
  715. per_cpu(ici_cpuid4_info, cpu) = NULL;
  716. }
  717. static int
  718. __cpuinit cpuid4_cache_lookup(int index, struct _cpuid4_info *this_leaf)
  719. {
  720. struct _cpuid4_info_regs *leaf_regs =
  721. (struct _cpuid4_info_regs *)this_leaf;
  722. return cpuid4_cache_lookup_regs(index, leaf_regs);
  723. }
  724. static void __cpuinit get_cpu_leaves(void *_retval)
  725. {
  726. int j, *retval = _retval, cpu = smp_processor_id();
  727. /* Do cpuid and store the results */
  728. for (j = 0; j < num_cache_leaves; j++) {
  729. struct _cpuid4_info *this_leaf;
  730. this_leaf = CPUID4_INFO_IDX(cpu, j);
  731. *retval = cpuid4_cache_lookup(j, this_leaf);
  732. if (unlikely(*retval < 0)) {
  733. int i;
  734. for (i = 0; i < j; i++)
  735. cache_remove_shared_cpu_map(cpu, i);
  736. break;
  737. }
  738. cache_shared_cpu_map_setup(cpu, j);
  739. }
  740. }
  741. static int __cpuinit detect_cache_attributes(unsigned int cpu)
  742. {
  743. int retval;
  744. if (num_cache_leaves == 0)
  745. return -ENOENT;
  746. per_cpu(ici_cpuid4_info, cpu) = kzalloc(
  747. sizeof(struct _cpuid4_info) * num_cache_leaves, GFP_KERNEL);
  748. if (per_cpu(ici_cpuid4_info, cpu) == NULL)
  749. return -ENOMEM;
  750. smp_call_function_single(cpu, get_cpu_leaves, &retval, true);
  751. if (retval) {
  752. kfree(per_cpu(ici_cpuid4_info, cpu));
  753. per_cpu(ici_cpuid4_info, cpu) = NULL;
  754. }
  755. return retval;
  756. }
  757. #include <linux/kobject.h>
  758. #include <linux/sysfs.h>
  759. extern struct sysdev_class cpu_sysdev_class; /* from drivers/base/cpu.c */
  760. /* pointer to kobject for cpuX/cache */
  761. static DEFINE_PER_CPU(struct kobject *, ici_cache_kobject);
  762. struct _index_kobject {
  763. struct kobject kobj;
  764. unsigned int cpu;
  765. unsigned short index;
  766. };
  767. /* pointer to array of kobjects for cpuX/cache/indexY */
  768. static DEFINE_PER_CPU(struct _index_kobject *, ici_index_kobject);
  769. #define INDEX_KOBJECT_PTR(x, y) (&((per_cpu(ici_index_kobject, x))[y]))
  770. #define show_one_plus(file_name, object, val) \
  771. static ssize_t show_##file_name \
  772. (struct _cpuid4_info *this_leaf, char *buf) \
  773. { \
  774. return sprintf(buf, "%lu\n", (unsigned long)this_leaf->object + val); \
  775. }
  776. show_one_plus(level, eax.split.level, 0);
  777. show_one_plus(coherency_line_size, ebx.split.coherency_line_size, 1);
  778. show_one_plus(physical_line_partition, ebx.split.physical_line_partition, 1);
  779. show_one_plus(ways_of_associativity, ebx.split.ways_of_associativity, 1);
  780. show_one_plus(number_of_sets, ecx.split.number_of_sets, 1);
  781. static ssize_t show_size(struct _cpuid4_info *this_leaf, char *buf)
  782. {
  783. return sprintf(buf, "%luK\n", this_leaf->size / 1024);
  784. }
  785. static ssize_t show_shared_cpu_map_func(struct _cpuid4_info *this_leaf,
  786. int type, char *buf)
  787. {
  788. ptrdiff_t len = PTR_ALIGN(buf + PAGE_SIZE - 1, PAGE_SIZE) - buf;
  789. int n = 0;
  790. if (len > 1) {
  791. const struct cpumask *mask;
  792. mask = to_cpumask(this_leaf->shared_cpu_map);
  793. n = type ?
  794. cpulist_scnprintf(buf, len-2, mask) :
  795. cpumask_scnprintf(buf, len-2, mask);
  796. buf[n++] = '\n';
  797. buf[n] = '\0';
  798. }
  799. return n;
  800. }
  801. static inline ssize_t show_shared_cpu_map(struct _cpuid4_info *leaf, char *buf)
  802. {
  803. return show_shared_cpu_map_func(leaf, 0, buf);
  804. }
  805. static inline ssize_t show_shared_cpu_list(struct _cpuid4_info *leaf, char *buf)
  806. {
  807. return show_shared_cpu_map_func(leaf, 1, buf);
  808. }
  809. static ssize_t show_type(struct _cpuid4_info *this_leaf, char *buf)
  810. {
  811. switch (this_leaf->eax.split.type) {
  812. case CACHE_TYPE_DATA:
  813. return sprintf(buf, "Data\n");
  814. case CACHE_TYPE_INST:
  815. return sprintf(buf, "Instruction\n");
  816. case CACHE_TYPE_UNIFIED:
  817. return sprintf(buf, "Unified\n");
  818. default:
  819. return sprintf(buf, "Unknown\n");
  820. }
  821. }
  822. #define to_object(k) container_of(k, struct _index_kobject, kobj)
  823. #define to_attr(a) container_of(a, struct _cache_attr, attr)
  824. #define define_one_ro(_name) \
  825. static struct _cache_attr _name = \
  826. __ATTR(_name, 0444, show_##_name, NULL)
  827. define_one_ro(level);
  828. define_one_ro(type);
  829. define_one_ro(coherency_line_size);
  830. define_one_ro(physical_line_partition);
  831. define_one_ro(ways_of_associativity);
  832. define_one_ro(number_of_sets);
  833. define_one_ro(size);
  834. define_one_ro(shared_cpu_map);
  835. define_one_ro(shared_cpu_list);
  836. #define DEFAULT_SYSFS_CACHE_ATTRS \
  837. &type.attr, \
  838. &level.attr, \
  839. &coherency_line_size.attr, \
  840. &physical_line_partition.attr, \
  841. &ways_of_associativity.attr, \
  842. &number_of_sets.attr, \
  843. &size.attr, \
  844. &shared_cpu_map.attr, \
  845. &shared_cpu_list.attr
  846. static struct attribute *default_attrs[] = {
  847. DEFAULT_SYSFS_CACHE_ATTRS,
  848. NULL
  849. };
  850. static struct attribute *default_l3_attrs[] = {
  851. DEFAULT_SYSFS_CACHE_ATTRS,
  852. #ifdef CONFIG_CPU_SUP_AMD
  853. &cache_disable_0.attr,
  854. &cache_disable_1.attr,
  855. #endif
  856. NULL
  857. };
  858. static ssize_t show(struct kobject *kobj, struct attribute *attr, char *buf)
  859. {
  860. struct _cache_attr *fattr = to_attr(attr);
  861. struct _index_kobject *this_leaf = to_object(kobj);
  862. ssize_t ret;
  863. ret = fattr->show ?
  864. fattr->show(CPUID4_INFO_IDX(this_leaf->cpu, this_leaf->index),
  865. buf) :
  866. 0;
  867. return ret;
  868. }
  869. static ssize_t store(struct kobject *kobj, struct attribute *attr,
  870. const char *buf, size_t count)
  871. {
  872. struct _cache_attr *fattr = to_attr(attr);
  873. struct _index_kobject *this_leaf = to_object(kobj);
  874. ssize_t ret;
  875. ret = fattr->store ?
  876. fattr->store(CPUID4_INFO_IDX(this_leaf->cpu, this_leaf->index),
  877. buf, count) :
  878. 0;
  879. return ret;
  880. }
  881. static const struct sysfs_ops sysfs_ops = {
  882. .show = show,
  883. .store = store,
  884. };
  885. static struct kobj_type ktype_cache = {
  886. .sysfs_ops = &sysfs_ops,
  887. .default_attrs = default_attrs,
  888. };
  889. static struct kobj_type ktype_percpu_entry = {
  890. .sysfs_ops = &sysfs_ops,
  891. };
  892. static void __cpuinit cpuid4_cache_sysfs_exit(unsigned int cpu)
  893. {
  894. kfree(per_cpu(ici_cache_kobject, cpu));
  895. kfree(per_cpu(ici_index_kobject, cpu));
  896. per_cpu(ici_cache_kobject, cpu) = NULL;
  897. per_cpu(ici_index_kobject, cpu) = NULL;
  898. free_cache_attributes(cpu);
  899. }
  900. static int __cpuinit cpuid4_cache_sysfs_init(unsigned int cpu)
  901. {
  902. int err;
  903. if (num_cache_leaves == 0)
  904. return -ENOENT;
  905. err = detect_cache_attributes(cpu);
  906. if (err)
  907. return err;
  908. /* Allocate all required memory */
  909. per_cpu(ici_cache_kobject, cpu) =
  910. kzalloc(sizeof(struct kobject), GFP_KERNEL);
  911. if (unlikely(per_cpu(ici_cache_kobject, cpu) == NULL))
  912. goto err_out;
  913. per_cpu(ici_index_kobject, cpu) = kzalloc(
  914. sizeof(struct _index_kobject) * num_cache_leaves, GFP_KERNEL);
  915. if (unlikely(per_cpu(ici_index_kobject, cpu) == NULL))
  916. goto err_out;
  917. return 0;
  918. err_out:
  919. cpuid4_cache_sysfs_exit(cpu);
  920. return -ENOMEM;
  921. }
  922. static DECLARE_BITMAP(cache_dev_map, NR_CPUS);
  923. /* Add/Remove cache interface for CPU device */
  924. static int __cpuinit cache_add_dev(struct sys_device * sys_dev)
  925. {
  926. unsigned int cpu = sys_dev->id;
  927. unsigned long i, j;
  928. struct _index_kobject *this_object;
  929. struct _cpuid4_info *this_leaf;
  930. int retval;
  931. retval = cpuid4_cache_sysfs_init(cpu);
  932. if (unlikely(retval < 0))
  933. return retval;
  934. retval = kobject_init_and_add(per_cpu(ici_cache_kobject, cpu),
  935. &ktype_percpu_entry,
  936. &sys_dev->kobj, "%s", "cache");
  937. if (retval < 0) {
  938. cpuid4_cache_sysfs_exit(cpu);
  939. return retval;
  940. }
  941. for (i = 0; i < num_cache_leaves; i++) {
  942. this_object = INDEX_KOBJECT_PTR(cpu, i);
  943. this_object->cpu = cpu;
  944. this_object->index = i;
  945. this_leaf = CPUID4_INFO_IDX(cpu, i);
  946. if (this_leaf->l3 && this_leaf->l3->can_disable)
  947. ktype_cache.default_attrs = default_l3_attrs;
  948. else
  949. ktype_cache.default_attrs = default_attrs;
  950. retval = kobject_init_and_add(&(this_object->kobj),
  951. &ktype_cache,
  952. per_cpu(ici_cache_kobject, cpu),
  953. "index%1lu", i);
  954. if (unlikely(retval)) {
  955. for (j = 0; j < i; j++)
  956. kobject_put(&(INDEX_KOBJECT_PTR(cpu, j)->kobj));
  957. kobject_put(per_cpu(ici_cache_kobject, cpu));
  958. cpuid4_cache_sysfs_exit(cpu);
  959. return retval;
  960. }
  961. kobject_uevent(&(this_object->kobj), KOBJ_ADD);
  962. }
  963. cpumask_set_cpu(cpu, to_cpumask(cache_dev_map));
  964. kobject_uevent(per_cpu(ici_cache_kobject, cpu), KOBJ_ADD);
  965. return 0;
  966. }
  967. static void __cpuinit cache_remove_dev(struct sys_device * sys_dev)
  968. {
  969. unsigned int cpu = sys_dev->id;
  970. unsigned long i;
  971. if (per_cpu(ici_cpuid4_info, cpu) == NULL)
  972. return;
  973. if (!cpumask_test_cpu(cpu, to_cpumask(cache_dev_map)))
  974. return;
  975. cpumask_clear_cpu(cpu, to_cpumask(cache_dev_map));
  976. for (i = 0; i < num_cache_leaves; i++)
  977. kobject_put(&(INDEX_KOBJECT_PTR(cpu, i)->kobj));
  978. kobject_put(per_cpu(ici_cache_kobject, cpu));
  979. cpuid4_cache_sysfs_exit(cpu);
  980. }
  981. static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
  982. unsigned long action, void *hcpu)
  983. {
  984. unsigned int cpu = (unsigned long)hcpu;
  985. struct sys_device *sys_dev;
  986. sys_dev = get_cpu_sysdev(cpu);
  987. switch (action) {
  988. case CPU_ONLINE:
  989. case CPU_ONLINE_FROZEN:
  990. cache_add_dev(sys_dev);
  991. break;
  992. case CPU_DEAD:
  993. case CPU_DEAD_FROZEN:
  994. cache_remove_dev(sys_dev);
  995. break;
  996. }
  997. return NOTIFY_OK;
  998. }
  999. static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
  1000. .notifier_call = cacheinfo_cpu_callback,
  1001. };
  1002. static int __cpuinit cache_sysfs_init(void)
  1003. {
  1004. int i;
  1005. if (num_cache_leaves == 0)
  1006. return 0;
  1007. for_each_online_cpu(i) {
  1008. int err;
  1009. struct sys_device *sys_dev = get_cpu_sysdev(i);
  1010. err = cache_add_dev(sys_dev);
  1011. if (err)
  1012. return err;
  1013. }
  1014. register_hotcpu_notifier(&cacheinfo_cpu_notifier);
  1015. return 0;
  1016. }
  1017. device_initcall(cache_sysfs_init);
  1018. #endif