salinfo.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  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/seq_file.h>
  43. #include <linux/module.h>
  44. #include <linux/smp.h>
  45. #include <linux/timer.h>
  46. #include <linux/vmalloc.h>
  47. #include <linux/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 const struct file_operations proc_salinfo_fops;
  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 const 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. wait_queue_head_t read_wait;
  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 decoded 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. static void
  169. salinfo_platform_oemdata_cpu(void *context)
  170. {
  171. struct salinfo_platform_oemdata_parms *parms = context;
  172. parms->ret = salinfo_platform_oemdata(parms->efi_guid, parms->oemdata, parms->oemdata_size);
  173. }
  174. static void
  175. shift1_data_saved (struct salinfo_data *data, int shift)
  176. {
  177. memcpy(data->data_saved+shift, data->data_saved+shift+1,
  178. (ARRAY_SIZE(data->data_saved) - (shift+1)) * sizeof(data->data_saved[0]));
  179. memset(data->data_saved + ARRAY_SIZE(data->data_saved) - 1, 0,
  180. sizeof(data->data_saved[0]));
  181. }
  182. /* This routine is invoked in interrupt context. Note: mca.c enables
  183. * interrupts before calling this code for CMC/CPE. MCA and INIT events are
  184. * not irq safe, do not call any routines that use spinlocks, they may deadlock.
  185. * MCA and INIT records are recorded, a timer event will look for any
  186. * outstanding events and wake up the user space code.
  187. *
  188. * The buffer passed from mca.c points to the output from ia64_log_get. This is
  189. * a persistent buffer but its contents can change between the interrupt and
  190. * when user space processes the record. Save the record id to identify
  191. * changes. If the buffer is NULL then just update the bitmap.
  192. */
  193. void
  194. salinfo_log_wakeup(int type, u8 *buffer, u64 size, int irqsafe)
  195. {
  196. struct salinfo_data *data = salinfo_data + type;
  197. struct salinfo_data_saved *data_saved;
  198. unsigned long flags = 0;
  199. int i;
  200. int saved_size = ARRAY_SIZE(data->data_saved);
  201. BUG_ON(type >= ARRAY_SIZE(salinfo_log_name));
  202. if (irqsafe)
  203. spin_lock_irqsave(&data_saved_lock, flags);
  204. if (buffer) {
  205. for (i = 0, data_saved = data->data_saved; i < saved_size; ++i, ++data_saved) {
  206. if (!data_saved->buffer)
  207. break;
  208. }
  209. if (i == saved_size) {
  210. if (!data->saved_num) {
  211. shift1_data_saved(data, 0);
  212. data_saved = data->data_saved + saved_size - 1;
  213. } else
  214. data_saved = NULL;
  215. }
  216. if (data_saved) {
  217. data_saved->cpu = smp_processor_id();
  218. data_saved->id = ((sal_log_record_header_t *)buffer)->id;
  219. data_saved->size = size;
  220. data_saved->buffer = buffer;
  221. }
  222. }
  223. cpumask_set_cpu(smp_processor_id(), &data->cpu_event);
  224. if (irqsafe) {
  225. wake_up_interruptible(&data->read_wait);
  226. spin_unlock_irqrestore(&data_saved_lock, flags);
  227. }
  228. }
  229. /* Check for outstanding MCA/INIT records every minute (arbitrary) */
  230. #define SALINFO_TIMER_DELAY (60*HZ)
  231. static struct timer_list salinfo_timer;
  232. extern void ia64_mlogbuf_dump(void);
  233. static void
  234. salinfo_timeout_check(struct salinfo_data *data)
  235. {
  236. if (!data->open)
  237. return;
  238. if (!cpumask_empty(&data->cpu_event))
  239. wake_up_interruptible(&data->read_wait);
  240. }
  241. static void
  242. salinfo_timeout (unsigned long arg)
  243. {
  244. ia64_mlogbuf_dump();
  245. salinfo_timeout_check(salinfo_data + SAL_INFO_TYPE_MCA);
  246. salinfo_timeout_check(salinfo_data + SAL_INFO_TYPE_INIT);
  247. salinfo_timer.expires = jiffies + SALINFO_TIMER_DELAY;
  248. add_timer(&salinfo_timer);
  249. }
  250. static int
  251. salinfo_event_open(struct inode *inode, struct file *file)
  252. {
  253. if (!capable(CAP_SYS_ADMIN))
  254. return -EPERM;
  255. return 0;
  256. }
  257. static ssize_t
  258. salinfo_event_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
  259. {
  260. struct salinfo_data *data = PDE_DATA(file_inode(file));
  261. char cmd[32];
  262. size_t size;
  263. int i, n, cpu = -1;
  264. retry:
  265. if (cpumask_empty(&data->cpu_event)) {
  266. if (file->f_flags & O_NONBLOCK)
  267. return -EAGAIN;
  268. if (wait_event_interruptible(data->read_wait,
  269. !cpumask_empty(&data->cpu_event)))
  270. return -EINTR;
  271. }
  272. n = data->cpu_check;
  273. for (i = 0; i < nr_cpu_ids; i++) {
  274. if (cpumask_test_cpu(n, &data->cpu_event)) {
  275. if (!cpu_online(n)) {
  276. cpumask_clear_cpu(n, &data->cpu_event);
  277. continue;
  278. }
  279. cpu = n;
  280. break;
  281. }
  282. if (++n == nr_cpu_ids)
  283. n = 0;
  284. }
  285. if (cpu == -1)
  286. goto retry;
  287. ia64_mlogbuf_dump();
  288. /* for next read, start checking at next CPU */
  289. data->cpu_check = cpu;
  290. if (++data->cpu_check == nr_cpu_ids)
  291. data->cpu_check = 0;
  292. snprintf(cmd, sizeof(cmd), "read %d\n", cpu);
  293. size = strlen(cmd);
  294. if (size > count)
  295. size = count;
  296. if (copy_to_user(buffer, cmd, size))
  297. return -EFAULT;
  298. return size;
  299. }
  300. static const struct file_operations salinfo_event_fops = {
  301. .open = salinfo_event_open,
  302. .read = salinfo_event_read,
  303. .llseek = noop_llseek,
  304. };
  305. static int
  306. salinfo_log_open(struct inode *inode, struct file *file)
  307. {
  308. struct salinfo_data *data = PDE_DATA(inode);
  309. if (!capable(CAP_SYS_ADMIN))
  310. return -EPERM;
  311. spin_lock(&data_lock);
  312. if (data->open) {
  313. spin_unlock(&data_lock);
  314. return -EBUSY;
  315. }
  316. data->open = 1;
  317. spin_unlock(&data_lock);
  318. if (data->state == STATE_NO_DATA &&
  319. !(data->log_buffer = vmalloc(ia64_sal_get_state_info_size(data->type)))) {
  320. data->open = 0;
  321. return -ENOMEM;
  322. }
  323. return 0;
  324. }
  325. static int
  326. salinfo_log_release(struct inode *inode, struct file *file)
  327. {
  328. struct salinfo_data *data = PDE_DATA(inode);
  329. if (data->state == STATE_NO_DATA) {
  330. vfree(data->log_buffer);
  331. vfree(data->oemdata);
  332. data->log_buffer = NULL;
  333. data->oemdata = NULL;
  334. }
  335. spin_lock(&data_lock);
  336. data->open = 0;
  337. spin_unlock(&data_lock);
  338. return 0;
  339. }
  340. static void
  341. call_on_cpu(int cpu, void (*fn)(void *), void *arg)
  342. {
  343. cpumask_t save_cpus_allowed = current->cpus_allowed;
  344. set_cpus_allowed_ptr(current, cpumask_of(cpu));
  345. (*fn)(arg);
  346. set_cpus_allowed_ptr(current, &save_cpus_allowed);
  347. }
  348. static void
  349. salinfo_log_read_cpu(void *context)
  350. {
  351. struct salinfo_data *data = context;
  352. sal_log_record_header_t *rh;
  353. data->log_size = ia64_sal_get_state_info(data->type, (u64 *) data->log_buffer);
  354. rh = (sal_log_record_header_t *)(data->log_buffer);
  355. /* Clear corrected errors as they are read from SAL */
  356. if (rh->severity == sal_log_severity_corrected)
  357. ia64_sal_clear_state_info(data->type);
  358. }
  359. static void
  360. salinfo_log_new_read(int cpu, struct salinfo_data *data)
  361. {
  362. struct salinfo_data_saved *data_saved;
  363. unsigned long flags;
  364. int i;
  365. int saved_size = ARRAY_SIZE(data->data_saved);
  366. data->saved_num = 0;
  367. spin_lock_irqsave(&data_saved_lock, flags);
  368. retry:
  369. for (i = 0, data_saved = data->data_saved; i < saved_size; ++i, ++data_saved) {
  370. if (data_saved->buffer && data_saved->cpu == cpu) {
  371. sal_log_record_header_t *rh = (sal_log_record_header_t *)(data_saved->buffer);
  372. data->log_size = data_saved->size;
  373. memcpy(data->log_buffer, rh, data->log_size);
  374. barrier(); /* id check must not be moved */
  375. if (rh->id == data_saved->id) {
  376. data->saved_num = i+1;
  377. break;
  378. }
  379. /* saved record changed by mca.c since interrupt, discard it */
  380. shift1_data_saved(data, i);
  381. goto retry;
  382. }
  383. }
  384. spin_unlock_irqrestore(&data_saved_lock, flags);
  385. if (!data->saved_num)
  386. call_on_cpu(cpu, salinfo_log_read_cpu, data);
  387. if (!data->log_size) {
  388. data->state = STATE_NO_DATA;
  389. cpumask_clear_cpu(cpu, &data->cpu_event);
  390. } else {
  391. data->state = STATE_LOG_RECORD;
  392. }
  393. }
  394. static ssize_t
  395. salinfo_log_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
  396. {
  397. struct salinfo_data *data = PDE_DATA(file_inode(file));
  398. u8 *buf;
  399. u64 bufsize;
  400. if (data->state == STATE_LOG_RECORD) {
  401. buf = data->log_buffer;
  402. bufsize = data->log_size;
  403. } else if (data->state == STATE_OEMDATA) {
  404. buf = data->oemdata;
  405. bufsize = data->oemdata_size;
  406. } else {
  407. buf = NULL;
  408. bufsize = 0;
  409. }
  410. return simple_read_from_buffer(buffer, count, ppos, buf, bufsize);
  411. }
  412. static void
  413. salinfo_log_clear_cpu(void *context)
  414. {
  415. struct salinfo_data *data = context;
  416. ia64_sal_clear_state_info(data->type);
  417. }
  418. static int
  419. salinfo_log_clear(struct salinfo_data *data, int cpu)
  420. {
  421. sal_log_record_header_t *rh;
  422. unsigned long flags;
  423. spin_lock_irqsave(&data_saved_lock, flags);
  424. data->state = STATE_NO_DATA;
  425. if (!cpumask_test_cpu(cpu, &data->cpu_event)) {
  426. spin_unlock_irqrestore(&data_saved_lock, flags);
  427. return 0;
  428. }
  429. cpumask_clear_cpu(cpu, &data->cpu_event);
  430. if (data->saved_num) {
  431. shift1_data_saved(data, data->saved_num - 1);
  432. data->saved_num = 0;
  433. }
  434. spin_unlock_irqrestore(&data_saved_lock, flags);
  435. rh = (sal_log_record_header_t *)(data->log_buffer);
  436. /* Corrected errors have already been cleared from SAL */
  437. if (rh->severity != sal_log_severity_corrected)
  438. call_on_cpu(cpu, salinfo_log_clear_cpu, data);
  439. /* clearing a record may make a new record visible */
  440. salinfo_log_new_read(cpu, data);
  441. if (data->state == STATE_LOG_RECORD) {
  442. spin_lock_irqsave(&data_saved_lock, flags);
  443. cpumask_set_cpu(cpu, &data->cpu_event);
  444. wake_up_interruptible(&data->read_wait);
  445. spin_unlock_irqrestore(&data_saved_lock, flags);
  446. }
  447. return 0;
  448. }
  449. static ssize_t
  450. salinfo_log_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
  451. {
  452. struct salinfo_data *data = PDE_DATA(file_inode(file));
  453. char cmd[32];
  454. size_t size;
  455. u32 offset;
  456. int cpu;
  457. size = sizeof(cmd);
  458. if (count < size)
  459. size = count;
  460. if (copy_from_user(cmd, buffer, size))
  461. return -EFAULT;
  462. if (sscanf(cmd, "read %d", &cpu) == 1) {
  463. salinfo_log_new_read(cpu, data);
  464. } else if (sscanf(cmd, "clear %d", &cpu) == 1) {
  465. int ret;
  466. if ((ret = salinfo_log_clear(data, cpu)))
  467. count = ret;
  468. } else if (sscanf(cmd, "oemdata %d %d", &cpu, &offset) == 2) {
  469. if (data->state != STATE_LOG_RECORD && data->state != STATE_OEMDATA)
  470. return -EINVAL;
  471. if (offset > data->log_size - sizeof(efi_guid_t))
  472. return -EINVAL;
  473. data->state = STATE_OEMDATA;
  474. if (salinfo_platform_oemdata) {
  475. struct salinfo_platform_oemdata_parms parms = {
  476. .efi_guid = data->log_buffer + offset,
  477. .oemdata = &data->oemdata,
  478. .oemdata_size = &data->oemdata_size
  479. };
  480. call_on_cpu(cpu, salinfo_platform_oemdata_cpu, &parms);
  481. if (parms.ret)
  482. count = parms.ret;
  483. } else
  484. data->oemdata_size = 0;
  485. } else
  486. return -EINVAL;
  487. return count;
  488. }
  489. static const struct file_operations salinfo_data_fops = {
  490. .open = salinfo_log_open,
  491. .release = salinfo_log_release,
  492. .read = salinfo_log_read,
  493. .write = salinfo_log_write,
  494. .llseek = default_llseek,
  495. };
  496. static int
  497. salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
  498. {
  499. unsigned int i, cpu = (unsigned long)hcpu;
  500. unsigned long flags;
  501. struct salinfo_data *data;
  502. switch (action) {
  503. case CPU_ONLINE:
  504. case CPU_ONLINE_FROZEN:
  505. spin_lock_irqsave(&data_saved_lock, flags);
  506. for (i = 0, data = salinfo_data;
  507. i < ARRAY_SIZE(salinfo_data);
  508. ++i, ++data) {
  509. cpumask_set_cpu(cpu, &data->cpu_event);
  510. wake_up_interruptible(&data->read_wait);
  511. }
  512. spin_unlock_irqrestore(&data_saved_lock, flags);
  513. break;
  514. case CPU_DEAD:
  515. case CPU_DEAD_FROZEN:
  516. spin_lock_irqsave(&data_saved_lock, flags);
  517. for (i = 0, data = salinfo_data;
  518. i < ARRAY_SIZE(salinfo_data);
  519. ++i, ++data) {
  520. struct salinfo_data_saved *data_saved;
  521. int j;
  522. for (j = ARRAY_SIZE(data->data_saved) - 1, data_saved = data->data_saved + j;
  523. j >= 0;
  524. --j, --data_saved) {
  525. if (data_saved->buffer && data_saved->cpu == cpu) {
  526. shift1_data_saved(data, j);
  527. }
  528. }
  529. cpumask_clear_cpu(cpu, &data->cpu_event);
  530. }
  531. spin_unlock_irqrestore(&data_saved_lock, flags);
  532. break;
  533. }
  534. return NOTIFY_OK;
  535. }
  536. static struct notifier_block salinfo_cpu_notifier =
  537. {
  538. .notifier_call = salinfo_cpu_callback,
  539. .priority = 0,
  540. };
  541. static int __init
  542. salinfo_init(void)
  543. {
  544. struct proc_dir_entry *salinfo_dir; /* /proc/sal dir entry */
  545. struct proc_dir_entry **sdir = salinfo_proc_entries; /* keeps track of every entry */
  546. struct proc_dir_entry *dir, *entry;
  547. struct salinfo_data *data;
  548. int i, j;
  549. salinfo_dir = proc_mkdir("sal", NULL);
  550. if (!salinfo_dir)
  551. return 0;
  552. for (i=0; i < NR_SALINFO_ENTRIES; i++) {
  553. /* pass the feature bit in question as misc data */
  554. *sdir++ = proc_create_data(salinfo_entries[i].name, 0, salinfo_dir,
  555. &proc_salinfo_fops,
  556. (void *)salinfo_entries[i].feature);
  557. }
  558. cpu_notifier_register_begin();
  559. for (i = 0; i < ARRAY_SIZE(salinfo_log_name); i++) {
  560. data = salinfo_data + i;
  561. data->type = i;
  562. init_waitqueue_head(&data->read_wait);
  563. dir = proc_mkdir(salinfo_log_name[i], salinfo_dir);
  564. if (!dir)
  565. continue;
  566. entry = proc_create_data("event", S_IRUSR, dir,
  567. &salinfo_event_fops, data);
  568. if (!entry)
  569. continue;
  570. *sdir++ = entry;
  571. entry = proc_create_data("data", S_IRUSR | S_IWUSR, dir,
  572. &salinfo_data_fops, data);
  573. if (!entry)
  574. continue;
  575. *sdir++ = entry;
  576. /* we missed any events before now */
  577. for_each_online_cpu(j)
  578. cpumask_set_cpu(j, &data->cpu_event);
  579. *sdir++ = dir;
  580. }
  581. *sdir++ = salinfo_dir;
  582. init_timer(&salinfo_timer);
  583. salinfo_timer.expires = jiffies + SALINFO_TIMER_DELAY;
  584. salinfo_timer.function = &salinfo_timeout;
  585. add_timer(&salinfo_timer);
  586. __register_hotcpu_notifier(&salinfo_cpu_notifier);
  587. cpu_notifier_register_done();
  588. return 0;
  589. }
  590. /*
  591. * 'data' contains an integer that corresponds to the feature we're
  592. * testing
  593. */
  594. static int proc_salinfo_show(struct seq_file *m, void *v)
  595. {
  596. unsigned long data = (unsigned long)v;
  597. seq_puts(m, (sal_platform_features & data) ? "1\n" : "0\n");
  598. return 0;
  599. }
  600. static int proc_salinfo_open(struct inode *inode, struct file *file)
  601. {
  602. return single_open(file, proc_salinfo_show, PDE_DATA(inode));
  603. }
  604. static const struct file_operations proc_salinfo_fops = {
  605. .open = proc_salinfo_open,
  606. .read = seq_read,
  607. .llseek = seq_lseek,
  608. .release = single_release,
  609. };
  610. module_init(salinfo_init);