salinfo.c 19 KB

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