salinfo.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. /*
  2. * salinfo.c
  3. *
  4. * Creates entries in /proc/sal for various system features.
  5. *
  6. * Copyright (c) 2003, 2006 Silicon Graphics, Inc. All rights reserved.
  7. * Copyright (c) 2003 Hewlett-Packard Co
  8. * Bjorn Helgaas <bjorn.helgaas@hp.com>
  9. *
  10. * 10/30/2001 jbarnes@sgi.com copied much of Stephane's palinfo
  11. * code to create this file
  12. * Oct 23 2003 kaos@sgi.com
  13. * Replace IPI with set_cpus_allowed() to read a record from the required cpu.
  14. * Redesign salinfo log processing to separate interrupt and user space
  15. * contexts.
  16. * Cache the record across multi-block reads from user space.
  17. * Support > 64 cpus.
  18. * Delete module_exit and MOD_INC/DEC_COUNT, salinfo cannot be a module.
  19. *
  20. * Jan 28 2004 kaos@sgi.com
  21. * Periodically check for outstanding MCA or INIT records.
  22. *
  23. * Dec 5 2004 kaos@sgi.com
  24. * Standardize which records are cleared automatically.
  25. *
  26. * Aug 18 2005 kaos@sgi.com
  27. * mca.c may not pass a buffer, a NULL buffer just indicates that a new
  28. * record is available in SAL.
  29. * Replace some NR_CPUS by cpus_online, for hotplug cpu.
  30. *
  31. * Jan 5 2006 kaos@sgi.com
  32. * Handle hotplug cpus coming online.
  33. * Handle hotplug cpus going offline while they still have outstanding records.
  34. * Use the cpu_* macros consistently.
  35. * Replace the counting semaphore with a mutex and a test if the cpumask is non-empty.
  36. * Modify the locking to make the test for "work to do" an atomic operation.
  37. */
  38. #include <linux/capability.h>
  39. #include <linux/cpu.h>
  40. #include <linux/types.h>
  41. #include <linux/proc_fs.h>
  42. #include <linux/module.h>
  43. #include <linux/smp.h>
  44. #include <linux/smp_lock.h>
  45. #include <linux/timer.h>
  46. #include <linux/vmalloc.h>
  47. #include <asm/semaphore.h>
  48. #include <asm/sal.h>
  49. #include <asm/uaccess.h>
  50. MODULE_AUTHOR("Jesse Barnes <jbarnes@sgi.com>");
  51. MODULE_DESCRIPTION("/proc interface to IA-64 SAL features");
  52. MODULE_LICENSE("GPL");
  53. static int salinfo_read(char *page, char **start, off_t off, int count, int *eof, void *data);
  54. typedef struct {
  55. const char *name; /* name of the proc entry */
  56. unsigned long feature; /* feature bit */
  57. struct proc_dir_entry *entry; /* registered entry (removal) */
  58. } salinfo_entry_t;
  59. /*
  60. * List {name,feature} pairs for every entry in /proc/sal/<feature>
  61. * that this module exports
  62. */
  63. static salinfo_entry_t salinfo_entries[]={
  64. { "bus_lock", IA64_SAL_PLATFORM_FEATURE_BUS_LOCK, },
  65. { "irq_redirection", IA64_SAL_PLATFORM_FEATURE_IRQ_REDIR_HINT, },
  66. { "ipi_redirection", IA64_SAL_PLATFORM_FEATURE_IPI_REDIR_HINT, },
  67. { "itc_drift", IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT, },
  68. };
  69. #define NR_SALINFO_ENTRIES ARRAY_SIZE(salinfo_entries)
  70. static char *salinfo_log_name[] = {
  71. "mca",
  72. "init",
  73. "cmc",
  74. "cpe",
  75. };
  76. static struct proc_dir_entry *salinfo_proc_entries[
  77. ARRAY_SIZE(salinfo_entries) + /* /proc/sal/bus_lock */
  78. ARRAY_SIZE(salinfo_log_name) + /* /proc/sal/{mca,...} */
  79. (2 * ARRAY_SIZE(salinfo_log_name)) + /* /proc/sal/mca/{event,data} */
  80. 1]; /* /proc/sal */
  81. /* Some records we get ourselves, some are accessed as saved data in buffers
  82. * that are owned by mca.c.
  83. */
  84. struct salinfo_data_saved {
  85. u8* buffer;
  86. u64 size;
  87. u64 id;
  88. int cpu;
  89. };
  90. /* State transitions. Actions are :-
  91. * Write "read <cpunum>" to the data file.
  92. * Write "clear <cpunum>" to the data file.
  93. * Write "oemdata <cpunum> <offset> to the data file.
  94. * Read from the data file.
  95. * Close the data file.
  96. *
  97. * Start state is NO_DATA.
  98. *
  99. * NO_DATA
  100. * write "read <cpunum>" -> NO_DATA or LOG_RECORD.
  101. * write "clear <cpunum>" -> NO_DATA or LOG_RECORD.
  102. * write "oemdata <cpunum> <offset> -> return -EINVAL.
  103. * read data -> return EOF.
  104. * close -> unchanged. Free record areas.
  105. *
  106. * LOG_RECORD
  107. * write "read <cpunum>" -> NO_DATA or LOG_RECORD.
  108. * write "clear <cpunum>" -> NO_DATA or LOG_RECORD.
  109. * write "oemdata <cpunum> <offset> -> format the oem data, goto OEMDATA.
  110. * read data -> return the INIT/MCA/CMC/CPE record.
  111. * close -> unchanged. Keep record areas.
  112. *
  113. * OEMDATA
  114. * write "read <cpunum>" -> NO_DATA or LOG_RECORD.
  115. * write "clear <cpunum>" -> NO_DATA or LOG_RECORD.
  116. * write "oemdata <cpunum> <offset> -> format the oem data, goto OEMDATA.
  117. * read data -> return the formatted oemdata.
  118. * close -> unchanged. Keep record areas.
  119. *
  120. * Closing the data file does not change the state. This allows shell scripts
  121. * to manipulate salinfo data, each shell redirection opens the file, does one
  122. * action then closes it again. The record areas are only freed at close when
  123. * the state is NO_DATA.
  124. */
  125. enum salinfo_state {
  126. STATE_NO_DATA,
  127. STATE_LOG_RECORD,
  128. STATE_OEMDATA,
  129. };
  130. struct salinfo_data {
  131. cpumask_t cpu_event; /* which cpus have outstanding events */
  132. struct semaphore mutex;
  133. u8 *log_buffer;
  134. u64 log_size;
  135. u8 *oemdata; /* decoded oem data */
  136. u64 oemdata_size;
  137. int open; /* single-open to prevent races */
  138. u8 type;
  139. u8 saved_num; /* using a saved record? */
  140. enum salinfo_state state :8; /* processing state */
  141. u8 padding;
  142. int cpu_check; /* next CPU to check */
  143. struct salinfo_data_saved data_saved[5];/* save last 5 records from mca.c, must be < 255 */
  144. };
  145. static struct salinfo_data salinfo_data[ARRAY_SIZE(salinfo_log_name)];
  146. static DEFINE_SPINLOCK(data_lock);
  147. static DEFINE_SPINLOCK(data_saved_lock);
  148. /** salinfo_platform_oemdata - optional callback to decode oemdata from an error
  149. * record.
  150. * @sect_header: pointer to the start of the section to decode.
  151. * @oemdata: returns vmalloc area containing the decded output.
  152. * @oemdata_size: returns length of decoded output (strlen).
  153. *
  154. * Description: If user space asks for oem data to be decoded by the kernel
  155. * and/or prom and the platform has set salinfo_platform_oemdata to the address
  156. * of a platform specific routine then call that routine. salinfo_platform_oemdata
  157. * vmalloc's and formats its output area, returning the address of the text
  158. * and its strlen. Returns 0 for success, -ve for error. The callback is
  159. * invoked on the cpu that generated the error record.
  160. */
  161. int (*salinfo_platform_oemdata)(const u8 *sect_header, u8 **oemdata, u64 *oemdata_size);
  162. struct salinfo_platform_oemdata_parms {
  163. const u8 *efi_guid;
  164. u8 **oemdata;
  165. u64 *oemdata_size;
  166. int ret;
  167. };
  168. /* Kick the mutex that tells user space that there is work to do. Instead of
  169. * trying to track the state of the mutex across multiple cpus, in user
  170. * context, interrupt context, non-maskable interrupt context and hotplug cpu,
  171. * it is far easier just to grab the mutex if it is free then release it.
  172. *
  173. * This routine must be called with data_saved_lock held, to make the down/up
  174. * operation atomic.
  175. */
  176. static void
  177. salinfo_work_to_do(struct salinfo_data *data)
  178. {
  179. down_trylock(&data->mutex);
  180. up(&data->mutex);
  181. }
  182. static void
  183. salinfo_platform_oemdata_cpu(void *context)
  184. {
  185. struct salinfo_platform_oemdata_parms *parms = context;
  186. parms->ret = salinfo_platform_oemdata(parms->efi_guid, parms->oemdata, parms->oemdata_size);
  187. }
  188. static void
  189. shift1_data_saved (struct salinfo_data *data, int shift)
  190. {
  191. memcpy(data->data_saved+shift, data->data_saved+shift+1,
  192. (ARRAY_SIZE(data->data_saved) - (shift+1)) * sizeof(data->data_saved[0]));
  193. memset(data->data_saved + ARRAY_SIZE(data->data_saved) - 1, 0,
  194. sizeof(data->data_saved[0]));
  195. }
  196. /* This routine is invoked in interrupt context. Note: mca.c enables
  197. * interrupts before calling this code for CMC/CPE. MCA and INIT events are
  198. * not irq safe, do not call any routines that use spinlocks, they may deadlock.
  199. * MCA and INIT records are recorded, a timer event will look for any
  200. * outstanding events and wake up the user space code.
  201. *
  202. * The buffer passed from mca.c points to the output from ia64_log_get. This is
  203. * a persistent buffer but its contents can change between the interrupt and
  204. * when user space processes the record. Save the record id to identify
  205. * changes. If the buffer is NULL then just update the bitmap.
  206. */
  207. void
  208. salinfo_log_wakeup(int type, u8 *buffer, u64 size, int irqsafe)
  209. {
  210. struct salinfo_data *data = salinfo_data + type;
  211. struct salinfo_data_saved *data_saved;
  212. unsigned long flags = 0;
  213. int i;
  214. int saved_size = ARRAY_SIZE(data->data_saved);
  215. BUG_ON(type >= ARRAY_SIZE(salinfo_log_name));
  216. if (irqsafe)
  217. spin_lock_irqsave(&data_saved_lock, flags);
  218. if (buffer) {
  219. for (i = 0, data_saved = data->data_saved; i < saved_size; ++i, ++data_saved) {
  220. if (!data_saved->buffer)
  221. break;
  222. }
  223. if (i == saved_size) {
  224. if (!data->saved_num) {
  225. shift1_data_saved(data, 0);
  226. data_saved = data->data_saved + saved_size - 1;
  227. } else
  228. data_saved = NULL;
  229. }
  230. if (data_saved) {
  231. data_saved->cpu = smp_processor_id();
  232. data_saved->id = ((sal_log_record_header_t *)buffer)->id;
  233. data_saved->size = size;
  234. data_saved->buffer = buffer;
  235. }
  236. }
  237. cpu_set(smp_processor_id(), data->cpu_event);
  238. if (irqsafe) {
  239. salinfo_work_to_do(data);
  240. spin_unlock_irqrestore(&data_saved_lock, flags);
  241. }
  242. }
  243. /* Check for outstanding MCA/INIT records every minute (arbitrary) */
  244. #define SALINFO_TIMER_DELAY (60*HZ)
  245. static struct timer_list salinfo_timer;
  246. extern void ia64_mlogbuf_dump(void);
  247. static void
  248. salinfo_timeout_check(struct salinfo_data *data)
  249. {
  250. unsigned long flags;
  251. if (!data->open)
  252. return;
  253. if (!cpus_empty(data->cpu_event)) {
  254. spin_lock_irqsave(&data_saved_lock, flags);
  255. salinfo_work_to_do(data);
  256. spin_unlock_irqrestore(&data_saved_lock, flags);
  257. }
  258. }
  259. static void
  260. salinfo_timeout (unsigned long arg)
  261. {
  262. ia64_mlogbuf_dump();
  263. salinfo_timeout_check(salinfo_data + SAL_INFO_TYPE_MCA);
  264. salinfo_timeout_check(salinfo_data + SAL_INFO_TYPE_INIT);
  265. salinfo_timer.expires = jiffies + SALINFO_TIMER_DELAY;
  266. add_timer(&salinfo_timer);
  267. }
  268. static int
  269. salinfo_event_open(struct inode *inode, struct file *file)
  270. {
  271. if (!capable(CAP_SYS_ADMIN))
  272. return -EPERM;
  273. return 0;
  274. }
  275. static ssize_t
  276. salinfo_event_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
  277. {
  278. struct inode *inode = file->f_dentry->d_inode;
  279. struct proc_dir_entry *entry = PDE(inode);
  280. struct salinfo_data *data = entry->data;
  281. char cmd[32];
  282. size_t size;
  283. int i, n, cpu = -1;
  284. retry:
  285. if (cpus_empty(data->cpu_event) && down_trylock(&data->mutex)) {
  286. if (file->f_flags & O_NONBLOCK)
  287. return -EAGAIN;
  288. if (down_interruptible(&data->mutex))
  289. return -EINTR;
  290. }
  291. n = data->cpu_check;
  292. for (i = 0; i < NR_CPUS; i++) {
  293. if (cpu_isset(n, data->cpu_event)) {
  294. if (!cpu_online(n)) {
  295. cpu_clear(n, data->cpu_event);
  296. continue;
  297. }
  298. cpu = n;
  299. break;
  300. }
  301. if (++n == NR_CPUS)
  302. n = 0;
  303. }
  304. if (cpu == -1)
  305. goto retry;
  306. ia64_mlogbuf_dump();
  307. /* for next read, start checking at next CPU */
  308. data->cpu_check = cpu;
  309. if (++data->cpu_check == NR_CPUS)
  310. data->cpu_check = 0;
  311. snprintf(cmd, sizeof(cmd), "read %d\n", cpu);
  312. size = strlen(cmd);
  313. if (size > count)
  314. size = count;
  315. if (copy_to_user(buffer, cmd, size))
  316. return -EFAULT;
  317. return size;
  318. }
  319. static struct file_operations salinfo_event_fops = {
  320. .open = salinfo_event_open,
  321. .read = salinfo_event_read,
  322. };
  323. static int
  324. salinfo_log_open(struct inode *inode, struct file *file)
  325. {
  326. struct proc_dir_entry *entry = PDE(inode);
  327. struct salinfo_data *data = entry->data;
  328. if (!capable(CAP_SYS_ADMIN))
  329. return -EPERM;
  330. spin_lock(&data_lock);
  331. if (data->open) {
  332. spin_unlock(&data_lock);
  333. return -EBUSY;
  334. }
  335. data->open = 1;
  336. spin_unlock(&data_lock);
  337. if (data->state == STATE_NO_DATA &&
  338. !(data->log_buffer = vmalloc(ia64_sal_get_state_info_size(data->type)))) {
  339. data->open = 0;
  340. return -ENOMEM;
  341. }
  342. return 0;
  343. }
  344. static int
  345. salinfo_log_release(struct inode *inode, struct file *file)
  346. {
  347. struct proc_dir_entry *entry = PDE(inode);
  348. struct salinfo_data *data = entry->data;
  349. if (data->state == STATE_NO_DATA) {
  350. vfree(data->log_buffer);
  351. vfree(data->oemdata);
  352. data->log_buffer = NULL;
  353. data->oemdata = NULL;
  354. }
  355. spin_lock(&data_lock);
  356. data->open = 0;
  357. spin_unlock(&data_lock);
  358. return 0;
  359. }
  360. static void
  361. call_on_cpu(int cpu, void (*fn)(void *), void *arg)
  362. {
  363. cpumask_t save_cpus_allowed = current->cpus_allowed;
  364. cpumask_t new_cpus_allowed = cpumask_of_cpu(cpu);
  365. set_cpus_allowed(current, new_cpus_allowed);
  366. (*fn)(arg);
  367. set_cpus_allowed(current, save_cpus_allowed);
  368. }
  369. static void
  370. salinfo_log_read_cpu(void *context)
  371. {
  372. struct salinfo_data *data = context;
  373. sal_log_record_header_t *rh;
  374. data->log_size = ia64_sal_get_state_info(data->type, (u64 *) data->log_buffer);
  375. rh = (sal_log_record_header_t *)(data->log_buffer);
  376. /* Clear corrected errors as they are read from SAL */
  377. if (rh->severity == sal_log_severity_corrected)
  378. ia64_sal_clear_state_info(data->type);
  379. }
  380. static void
  381. salinfo_log_new_read(int cpu, struct salinfo_data *data)
  382. {
  383. struct salinfo_data_saved *data_saved;
  384. unsigned long flags;
  385. int i;
  386. int saved_size = ARRAY_SIZE(data->data_saved);
  387. data->saved_num = 0;
  388. spin_lock_irqsave(&data_saved_lock, flags);
  389. retry:
  390. for (i = 0, data_saved = data->data_saved; i < saved_size; ++i, ++data_saved) {
  391. if (data_saved->buffer && data_saved->cpu == cpu) {
  392. sal_log_record_header_t *rh = (sal_log_record_header_t *)(data_saved->buffer);
  393. data->log_size = data_saved->size;
  394. memcpy(data->log_buffer, rh, data->log_size);
  395. barrier(); /* id check must not be moved */
  396. if (rh->id == data_saved->id) {
  397. data->saved_num = i+1;
  398. break;
  399. }
  400. /* saved record changed by mca.c since interrupt, discard it */
  401. shift1_data_saved(data, i);
  402. goto retry;
  403. }
  404. }
  405. spin_unlock_irqrestore(&data_saved_lock, flags);
  406. if (!data->saved_num)
  407. call_on_cpu(cpu, salinfo_log_read_cpu, data);
  408. if (!data->log_size) {
  409. data->state = STATE_NO_DATA;
  410. cpu_clear(cpu, data->cpu_event);
  411. } else {
  412. data->state = STATE_LOG_RECORD;
  413. }
  414. }
  415. static ssize_t
  416. salinfo_log_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
  417. {
  418. struct inode *inode = file->f_dentry->d_inode;
  419. struct proc_dir_entry *entry = PDE(inode);
  420. struct salinfo_data *data = entry->data;
  421. u8 *buf;
  422. u64 bufsize;
  423. if (data->state == STATE_LOG_RECORD) {
  424. buf = data->log_buffer;
  425. bufsize = data->log_size;
  426. } else if (data->state == STATE_OEMDATA) {
  427. buf = data->oemdata;
  428. bufsize = data->oemdata_size;
  429. } else {
  430. buf = NULL;
  431. bufsize = 0;
  432. }
  433. return simple_read_from_buffer(buffer, count, ppos, buf, bufsize);
  434. }
  435. static void
  436. salinfo_log_clear_cpu(void *context)
  437. {
  438. struct salinfo_data *data = context;
  439. ia64_sal_clear_state_info(data->type);
  440. }
  441. static int
  442. salinfo_log_clear(struct salinfo_data *data, int cpu)
  443. {
  444. sal_log_record_header_t *rh;
  445. unsigned long flags;
  446. spin_lock_irqsave(&data_saved_lock, flags);
  447. data->state = STATE_NO_DATA;
  448. if (!cpu_isset(cpu, data->cpu_event)) {
  449. spin_unlock_irqrestore(&data_saved_lock, flags);
  450. return 0;
  451. }
  452. cpu_clear(cpu, data->cpu_event);
  453. if (data->saved_num) {
  454. shift1_data_saved(data, data->saved_num - 1);
  455. data->saved_num = 0;
  456. }
  457. spin_unlock_irqrestore(&data_saved_lock, flags);
  458. rh = (sal_log_record_header_t *)(data->log_buffer);
  459. /* Corrected errors have already been cleared from SAL */
  460. if (rh->severity != sal_log_severity_corrected)
  461. call_on_cpu(cpu, salinfo_log_clear_cpu, data);
  462. /* clearing a record may make a new record visible */
  463. salinfo_log_new_read(cpu, data);
  464. if (data->state == STATE_LOG_RECORD) {
  465. spin_lock_irqsave(&data_saved_lock, flags);
  466. cpu_set(cpu, data->cpu_event);
  467. salinfo_work_to_do(data);
  468. spin_unlock_irqrestore(&data_saved_lock, flags);
  469. }
  470. return 0;
  471. }
  472. static ssize_t
  473. salinfo_log_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
  474. {
  475. struct inode *inode = file->f_dentry->d_inode;
  476. struct proc_dir_entry *entry = PDE(inode);
  477. struct salinfo_data *data = entry->data;
  478. char cmd[32];
  479. size_t size;
  480. u32 offset;
  481. int cpu;
  482. size = sizeof(cmd);
  483. if (count < size)
  484. size = count;
  485. if (copy_from_user(cmd, buffer, size))
  486. return -EFAULT;
  487. if (sscanf(cmd, "read %d", &cpu) == 1) {
  488. salinfo_log_new_read(cpu, data);
  489. } else if (sscanf(cmd, "clear %d", &cpu) == 1) {
  490. int ret;
  491. if ((ret = salinfo_log_clear(data, cpu)))
  492. count = ret;
  493. } else if (sscanf(cmd, "oemdata %d %d", &cpu, &offset) == 2) {
  494. if (data->state != STATE_LOG_RECORD && data->state != STATE_OEMDATA)
  495. return -EINVAL;
  496. if (offset > data->log_size - sizeof(efi_guid_t))
  497. return -EINVAL;
  498. data->state = STATE_OEMDATA;
  499. if (salinfo_platform_oemdata) {
  500. struct salinfo_platform_oemdata_parms parms = {
  501. .efi_guid = data->log_buffer + offset,
  502. .oemdata = &data->oemdata,
  503. .oemdata_size = &data->oemdata_size
  504. };
  505. call_on_cpu(cpu, salinfo_platform_oemdata_cpu, &parms);
  506. if (parms.ret)
  507. count = parms.ret;
  508. } else
  509. data->oemdata_size = 0;
  510. } else
  511. return -EINVAL;
  512. return count;
  513. }
  514. static struct file_operations salinfo_data_fops = {
  515. .open = salinfo_log_open,
  516. .release = salinfo_log_release,
  517. .read = salinfo_log_read,
  518. .write = salinfo_log_write,
  519. };
  520. #ifdef CONFIG_HOTPLUG_CPU
  521. static int __devinit
  522. salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
  523. {
  524. unsigned int i, cpu = (unsigned long)hcpu;
  525. unsigned long flags;
  526. struct salinfo_data *data;
  527. switch (action) {
  528. case CPU_ONLINE:
  529. spin_lock_irqsave(&data_saved_lock, flags);
  530. for (i = 0, data = salinfo_data;
  531. i < ARRAY_SIZE(salinfo_data);
  532. ++i, ++data) {
  533. cpu_set(cpu, data->cpu_event);
  534. salinfo_work_to_do(data);
  535. }
  536. spin_unlock_irqrestore(&data_saved_lock, flags);
  537. break;
  538. case CPU_DEAD:
  539. spin_lock_irqsave(&data_saved_lock, flags);
  540. for (i = 0, data = salinfo_data;
  541. i < ARRAY_SIZE(salinfo_data);
  542. ++i, ++data) {
  543. struct salinfo_data_saved *data_saved;
  544. int j;
  545. for (j = ARRAY_SIZE(data->data_saved) - 1, data_saved = data->data_saved + j;
  546. j >= 0;
  547. --j, --data_saved) {
  548. if (data_saved->buffer && data_saved->cpu == cpu) {
  549. shift1_data_saved(data, j);
  550. }
  551. }
  552. cpu_clear(cpu, data->cpu_event);
  553. }
  554. spin_unlock_irqrestore(&data_saved_lock, flags);
  555. break;
  556. }
  557. return NOTIFY_OK;
  558. }
  559. static struct notifier_block salinfo_cpu_notifier =
  560. {
  561. .notifier_call = salinfo_cpu_callback,
  562. .priority = 0,
  563. };
  564. #endif /* CONFIG_HOTPLUG_CPU */
  565. static int __init
  566. salinfo_init(void)
  567. {
  568. struct proc_dir_entry *salinfo_dir; /* /proc/sal dir entry */
  569. struct proc_dir_entry **sdir = salinfo_proc_entries; /* keeps track of every entry */
  570. struct proc_dir_entry *dir, *entry;
  571. struct salinfo_data *data;
  572. int i, j;
  573. salinfo_dir = proc_mkdir("sal", NULL);
  574. if (!salinfo_dir)
  575. return 0;
  576. for (i=0; i < NR_SALINFO_ENTRIES; i++) {
  577. /* pass the feature bit in question as misc data */
  578. *sdir++ = create_proc_read_entry (salinfo_entries[i].name, 0, salinfo_dir,
  579. salinfo_read, (void *)salinfo_entries[i].feature);
  580. }
  581. for (i = 0; i < ARRAY_SIZE(salinfo_log_name); i++) {
  582. data = salinfo_data + i;
  583. data->type = i;
  584. init_MUTEX(&data->mutex);
  585. dir = proc_mkdir(salinfo_log_name[i], salinfo_dir);
  586. if (!dir)
  587. continue;
  588. entry = create_proc_entry("event", S_IRUSR, dir);
  589. if (!entry)
  590. continue;
  591. entry->data = data;
  592. entry->proc_fops = &salinfo_event_fops;
  593. *sdir++ = entry;
  594. entry = create_proc_entry("data", S_IRUSR | S_IWUSR, dir);
  595. if (!entry)
  596. continue;
  597. entry->data = data;
  598. entry->proc_fops = &salinfo_data_fops;
  599. *sdir++ = entry;
  600. /* we missed any events before now */
  601. for_each_online_cpu(j)
  602. cpu_set(j, data->cpu_event);
  603. *sdir++ = dir;
  604. }
  605. *sdir++ = salinfo_dir;
  606. init_timer(&salinfo_timer);
  607. salinfo_timer.expires = jiffies + SALINFO_TIMER_DELAY;
  608. salinfo_timer.function = &salinfo_timeout;
  609. add_timer(&salinfo_timer);
  610. register_hotcpu_notifier(&salinfo_cpu_notifier);
  611. return 0;
  612. }
  613. /*
  614. * 'data' contains an integer that corresponds to the feature we're
  615. * testing
  616. */
  617. static int
  618. salinfo_read(char *page, char **start, off_t off, int count, int *eof, void *data)
  619. {
  620. int len = 0;
  621. len = sprintf(page, (sal_platform_features & (unsigned long)data) ? "1\n" : "0\n");
  622. if (len <= off+count) *eof = 1;
  623. *start = page + off;
  624. len -= off;
  625. if (len>count) len = count;
  626. if (len<0) len = 0;
  627. return len;
  628. }
  629. module_init(salinfo_init);