salinfo.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * salinfo.c
  4. *
  5. * Creates entries in /proc/sal for various system features.
  6. *
  7. * Copyright (c) 2003, 2006 Silicon Graphics, Inc. All rights reserved.
  8. * Copyright (c) 2003 Hewlett-Packard Co
  9. * Bjorn Helgaas <[email protected]>
  10. *
  11. * 10/30/2001 [email protected] copied much of Stephane's palinfo
  12. * code to create this file
  13. * Oct 23 2003 [email protected]
  14. * Replace IPI with set_cpus_allowed() to read a record from the required cpu.
  15. * Redesign salinfo log processing to separate interrupt and user space
  16. * contexts.
  17. * Cache the record across multi-block reads from user space.
  18. * Support > 64 cpus.
  19. * Delete module_exit and MOD_INC/DEC_COUNT, salinfo cannot be a module.
  20. *
  21. * Jan 28 2004 [email protected]
  22. * Periodically check for outstanding MCA or INIT records.
  23. *
  24. * Dec 5 2004 [email protected]
  25. * Standardize which records are cleared automatically.
  26. *
  27. * Aug 18 2005 [email protected]
  28. * mca.c may not pass a buffer, a NULL buffer just indicates that a new
  29. * record is available in SAL.
  30. * Replace some NR_CPUS by cpus_online, for hotplug cpu.
  31. *
  32. * Jan 5 2006 [email protected]
  33. * Handle hotplug cpus coming online.
  34. * Handle hotplug cpus going offline while they still have outstanding records.
  35. * Use the cpu_* macros consistently.
  36. * Replace the counting semaphore with a mutex and a test if the cpumask is non-empty.
  37. * Modify the locking to make the test for "work to do" an atomic operation.
  38. */
  39. #include <linux/capability.h>
  40. #include <linux/cpu.h>
  41. #include <linux/types.h>
  42. #include <linux/proc_fs.h>
  43. #include <linux/seq_file.h>
  44. #include <linux/module.h>
  45. #include <linux/smp.h>
  46. #include <linux/timer.h>
  47. #include <linux/vmalloc.h>
  48. #include <linux/semaphore.h>
  49. #include <asm/sal.h>
  50. #include <linux/uaccess.h>
  51. MODULE_AUTHOR("Jesse Barnes <[email protected]>");
  52. MODULE_DESCRIPTION("/proc interface to IA-64 SAL features");
  53. MODULE_LICENSE("GPL");
  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. };
  167. static long
  168. salinfo_platform_oemdata_cpu(void *context)
  169. {
  170. struct salinfo_platform_oemdata_parms *parms = context;
  171. return salinfo_platform_oemdata(parms->efi_guid, parms->oemdata, parms->oemdata_size);
  172. }
  173. static void
  174. shift1_data_saved (struct salinfo_data *data, int shift)
  175. {
  176. memcpy(data->data_saved+shift, data->data_saved+shift+1,
  177. (ARRAY_SIZE(data->data_saved) - (shift+1)) * sizeof(data->data_saved[0]));
  178. memset(data->data_saved + ARRAY_SIZE(data->data_saved) - 1, 0,
  179. sizeof(data->data_saved[0]));
  180. }
  181. /* This routine is invoked in interrupt context. Note: mca.c enables
  182. * interrupts before calling this code for CMC/CPE. MCA and INIT events are
  183. * not irq safe, do not call any routines that use spinlocks, they may deadlock.
  184. * MCA and INIT records are recorded, a timer event will look for any
  185. * outstanding events and wake up the user space code.
  186. *
  187. * The buffer passed from mca.c points to the output from ia64_log_get. This is
  188. * a persistent buffer but its contents can change between the interrupt and
  189. * when user space processes the record. Save the record id to identify
  190. * changes. If the buffer is NULL then just update the bitmap.
  191. */
  192. void
  193. salinfo_log_wakeup(int type, u8 *buffer, u64 size, int irqsafe)
  194. {
  195. struct salinfo_data *data = salinfo_data + type;
  196. struct salinfo_data_saved *data_saved;
  197. unsigned long flags = 0;
  198. int i;
  199. int saved_size = ARRAY_SIZE(data->data_saved);
  200. BUG_ON(type >= ARRAY_SIZE(salinfo_log_name));
  201. if (irqsafe)
  202. spin_lock_irqsave(&data_saved_lock, flags);
  203. if (buffer) {
  204. for (i = 0, data_saved = data->data_saved; i < saved_size; ++i, ++data_saved) {
  205. if (!data_saved->buffer)
  206. break;
  207. }
  208. if (i == saved_size) {
  209. if (!data->saved_num) {
  210. shift1_data_saved(data, 0);
  211. data_saved = data->data_saved + saved_size - 1;
  212. } else
  213. data_saved = NULL;
  214. }
  215. if (data_saved) {
  216. data_saved->cpu = smp_processor_id();
  217. data_saved->id = ((sal_log_record_header_t *)buffer)->id;
  218. data_saved->size = size;
  219. data_saved->buffer = buffer;
  220. }
  221. }
  222. cpumask_set_cpu(smp_processor_id(), &data->cpu_event);
  223. if (irqsafe) {
  224. wake_up_interruptible(&data->read_wait);
  225. spin_unlock_irqrestore(&data_saved_lock, flags);
  226. }
  227. }
  228. /* Check for outstanding MCA/INIT records every minute (arbitrary) */
  229. #define SALINFO_TIMER_DELAY (60*HZ)
  230. static struct timer_list salinfo_timer;
  231. extern void ia64_mlogbuf_dump(void);
  232. static void
  233. salinfo_timeout_check(struct salinfo_data *data)
  234. {
  235. if (!data->open)
  236. return;
  237. if (!cpumask_empty(&data->cpu_event))
  238. wake_up_interruptible(&data->read_wait);
  239. }
  240. static void
  241. salinfo_timeout(struct timer_list *unused)
  242. {
  243. ia64_mlogbuf_dump();
  244. salinfo_timeout_check(salinfo_data + SAL_INFO_TYPE_MCA);
  245. salinfo_timeout_check(salinfo_data + SAL_INFO_TYPE_INIT);
  246. salinfo_timer.expires = jiffies + SALINFO_TIMER_DELAY;
  247. add_timer(&salinfo_timer);
  248. }
  249. static int
  250. salinfo_event_open(struct inode *inode, struct file *file)
  251. {
  252. if (!capable(CAP_SYS_ADMIN))
  253. return -EPERM;
  254. return 0;
  255. }
  256. static ssize_t
  257. salinfo_event_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
  258. {
  259. struct salinfo_data *data = pde_data(file_inode(file));
  260. char cmd[32];
  261. size_t size;
  262. int i, n, cpu = -1;
  263. retry:
  264. if (cpumask_empty(&data->cpu_event)) {
  265. if (file->f_flags & O_NONBLOCK)
  266. return -EAGAIN;
  267. if (wait_event_interruptible(data->read_wait,
  268. !cpumask_empty(&data->cpu_event)))
  269. return -EINTR;
  270. }
  271. n = data->cpu_check;
  272. for (i = 0; i < nr_cpu_ids; i++) {
  273. if (cpumask_test_cpu(n, &data->cpu_event)) {
  274. if (!cpu_online(n)) {
  275. cpumask_clear_cpu(n, &data->cpu_event);
  276. continue;
  277. }
  278. cpu = n;
  279. break;
  280. }
  281. if (++n == nr_cpu_ids)
  282. n = 0;
  283. }
  284. if (cpu == -1)
  285. goto retry;
  286. ia64_mlogbuf_dump();
  287. /* for next read, start checking at next CPU */
  288. data->cpu_check = cpu;
  289. if (++data->cpu_check == nr_cpu_ids)
  290. data->cpu_check = 0;
  291. snprintf(cmd, sizeof(cmd), "read %d\n", cpu);
  292. size = strlen(cmd);
  293. if (size > count)
  294. size = count;
  295. if (copy_to_user(buffer, cmd, size))
  296. return -EFAULT;
  297. return size;
  298. }
  299. static const struct proc_ops salinfo_event_proc_ops = {
  300. .proc_open = salinfo_event_open,
  301. .proc_read = salinfo_event_read,
  302. .proc_lseek = noop_llseek,
  303. };
  304. static int
  305. salinfo_log_open(struct inode *inode, struct file *file)
  306. {
  307. struct salinfo_data *data = pde_data(inode);
  308. if (!capable(CAP_SYS_ADMIN))
  309. return -EPERM;
  310. spin_lock(&data_lock);
  311. if (data->open) {
  312. spin_unlock(&data_lock);
  313. return -EBUSY;
  314. }
  315. data->open = 1;
  316. spin_unlock(&data_lock);
  317. if (data->state == STATE_NO_DATA &&
  318. !(data->log_buffer = vmalloc(ia64_sal_get_state_info_size(data->type)))) {
  319. data->open = 0;
  320. return -ENOMEM;
  321. }
  322. return 0;
  323. }
  324. static int
  325. salinfo_log_release(struct inode *inode, struct file *file)
  326. {
  327. struct salinfo_data *data = pde_data(inode);
  328. if (data->state == STATE_NO_DATA) {
  329. vfree(data->log_buffer);
  330. vfree(data->oemdata);
  331. data->log_buffer = NULL;
  332. data->oemdata = NULL;
  333. }
  334. spin_lock(&data_lock);
  335. data->open = 0;
  336. spin_unlock(&data_lock);
  337. return 0;
  338. }
  339. static long
  340. salinfo_log_read_cpu(void *context)
  341. {
  342. struct salinfo_data *data = context;
  343. sal_log_record_header_t *rh;
  344. data->log_size = ia64_sal_get_state_info(data->type, (u64 *) data->log_buffer);
  345. rh = (sal_log_record_header_t *)(data->log_buffer);
  346. /* Clear corrected errors as they are read from SAL */
  347. if (rh->severity == sal_log_severity_corrected)
  348. ia64_sal_clear_state_info(data->type);
  349. return 0;
  350. }
  351. static void
  352. salinfo_log_new_read(int cpu, struct salinfo_data *data)
  353. {
  354. struct salinfo_data_saved *data_saved;
  355. unsigned long flags;
  356. int i;
  357. int saved_size = ARRAY_SIZE(data->data_saved);
  358. data->saved_num = 0;
  359. spin_lock_irqsave(&data_saved_lock, flags);
  360. retry:
  361. for (i = 0, data_saved = data->data_saved; i < saved_size; ++i, ++data_saved) {
  362. if (data_saved->buffer && data_saved->cpu == cpu) {
  363. sal_log_record_header_t *rh = (sal_log_record_header_t *)(data_saved->buffer);
  364. data->log_size = data_saved->size;
  365. memcpy(data->log_buffer, rh, data->log_size);
  366. barrier(); /* id check must not be moved */
  367. if (rh->id == data_saved->id) {
  368. data->saved_num = i+1;
  369. break;
  370. }
  371. /* saved record changed by mca.c since interrupt, discard it */
  372. shift1_data_saved(data, i);
  373. goto retry;
  374. }
  375. }
  376. spin_unlock_irqrestore(&data_saved_lock, flags);
  377. if (!data->saved_num)
  378. work_on_cpu_safe(cpu, salinfo_log_read_cpu, data);
  379. if (!data->log_size) {
  380. data->state = STATE_NO_DATA;
  381. cpumask_clear_cpu(cpu, &data->cpu_event);
  382. } else {
  383. data->state = STATE_LOG_RECORD;
  384. }
  385. }
  386. static ssize_t
  387. salinfo_log_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
  388. {
  389. struct salinfo_data *data = pde_data(file_inode(file));
  390. u8 *buf;
  391. u64 bufsize;
  392. if (data->state == STATE_LOG_RECORD) {
  393. buf = data->log_buffer;
  394. bufsize = data->log_size;
  395. } else if (data->state == STATE_OEMDATA) {
  396. buf = data->oemdata;
  397. bufsize = data->oemdata_size;
  398. } else {
  399. buf = NULL;
  400. bufsize = 0;
  401. }
  402. return simple_read_from_buffer(buffer, count, ppos, buf, bufsize);
  403. }
  404. static long
  405. salinfo_log_clear_cpu(void *context)
  406. {
  407. struct salinfo_data *data = context;
  408. ia64_sal_clear_state_info(data->type);
  409. return 0;
  410. }
  411. static int
  412. salinfo_log_clear(struct salinfo_data *data, int cpu)
  413. {
  414. sal_log_record_header_t *rh;
  415. unsigned long flags;
  416. spin_lock_irqsave(&data_saved_lock, flags);
  417. data->state = STATE_NO_DATA;
  418. if (!cpumask_test_cpu(cpu, &data->cpu_event)) {
  419. spin_unlock_irqrestore(&data_saved_lock, flags);
  420. return 0;
  421. }
  422. cpumask_clear_cpu(cpu, &data->cpu_event);
  423. if (data->saved_num) {
  424. shift1_data_saved(data, data->saved_num - 1);
  425. data->saved_num = 0;
  426. }
  427. spin_unlock_irqrestore(&data_saved_lock, flags);
  428. rh = (sal_log_record_header_t *)(data->log_buffer);
  429. /* Corrected errors have already been cleared from SAL */
  430. if (rh->severity != sal_log_severity_corrected)
  431. work_on_cpu_safe(cpu, salinfo_log_clear_cpu, data);
  432. /* clearing a record may make a new record visible */
  433. salinfo_log_new_read(cpu, data);
  434. if (data->state == STATE_LOG_RECORD) {
  435. spin_lock_irqsave(&data_saved_lock, flags);
  436. cpumask_set_cpu(cpu, &data->cpu_event);
  437. wake_up_interruptible(&data->read_wait);
  438. spin_unlock_irqrestore(&data_saved_lock, flags);
  439. }
  440. return 0;
  441. }
  442. static ssize_t
  443. salinfo_log_write(struct file *file, const char __user *buffer, size_t count, loff_t *ppos)
  444. {
  445. struct salinfo_data *data = pde_data(file_inode(file));
  446. char cmd[32];
  447. size_t size;
  448. u32 offset;
  449. int cpu;
  450. size = sizeof(cmd);
  451. if (count < size)
  452. size = count;
  453. if (copy_from_user(cmd, buffer, size))
  454. return -EFAULT;
  455. if (sscanf(cmd, "read %d", &cpu) == 1) {
  456. salinfo_log_new_read(cpu, data);
  457. } else if (sscanf(cmd, "clear %d", &cpu) == 1) {
  458. int ret;
  459. if ((ret = salinfo_log_clear(data, cpu)))
  460. count = ret;
  461. } else if (sscanf(cmd, "oemdata %d %d", &cpu, &offset) == 2) {
  462. if (data->state != STATE_LOG_RECORD && data->state != STATE_OEMDATA)
  463. return -EINVAL;
  464. if (offset > data->log_size - sizeof(efi_guid_t))
  465. return -EINVAL;
  466. data->state = STATE_OEMDATA;
  467. if (salinfo_platform_oemdata) {
  468. struct salinfo_platform_oemdata_parms parms = {
  469. .efi_guid = data->log_buffer + offset,
  470. .oemdata = &data->oemdata,
  471. .oemdata_size = &data->oemdata_size
  472. };
  473. count = work_on_cpu_safe(cpu, salinfo_platform_oemdata_cpu,
  474. &parms);
  475. } else
  476. data->oemdata_size = 0;
  477. } else
  478. return -EINVAL;
  479. return count;
  480. }
  481. static const struct proc_ops salinfo_data_proc_ops = {
  482. .proc_open = salinfo_log_open,
  483. .proc_release = salinfo_log_release,
  484. .proc_read = salinfo_log_read,
  485. .proc_write = salinfo_log_write,
  486. .proc_lseek = default_llseek,
  487. };
  488. static int salinfo_cpu_online(unsigned int cpu)
  489. {
  490. unsigned int i, end = ARRAY_SIZE(salinfo_data);
  491. struct salinfo_data *data;
  492. spin_lock_irq(&data_saved_lock);
  493. for (i = 0, data = salinfo_data; i < end; ++i, ++data) {
  494. cpumask_set_cpu(cpu, &data->cpu_event);
  495. wake_up_interruptible(&data->read_wait);
  496. }
  497. spin_unlock_irq(&data_saved_lock);
  498. return 0;
  499. }
  500. static int salinfo_cpu_pre_down(unsigned int cpu)
  501. {
  502. unsigned int i, end = ARRAY_SIZE(salinfo_data);
  503. struct salinfo_data *data;
  504. spin_lock_irq(&data_saved_lock);
  505. for (i = 0, data = salinfo_data; i < end; ++i, ++data) {
  506. struct salinfo_data_saved *data_saved;
  507. int j = ARRAY_SIZE(data->data_saved) - 1;
  508. for (data_saved = data->data_saved + j; j >= 0;
  509. --j, --data_saved) {
  510. if (data_saved->buffer && data_saved->cpu == cpu)
  511. shift1_data_saved(data, j);
  512. }
  513. cpumask_clear_cpu(cpu, &data->cpu_event);
  514. }
  515. spin_unlock_irq(&data_saved_lock);
  516. return 0;
  517. }
  518. /*
  519. * 'data' contains an integer that corresponds to the feature we're
  520. * testing
  521. */
  522. static int __maybe_unused proc_salinfo_show(struct seq_file *m, void *v)
  523. {
  524. unsigned long data = (unsigned long)v;
  525. seq_puts(m, (sal_platform_features & data) ? "1\n" : "0\n");
  526. return 0;
  527. }
  528. static int __init
  529. salinfo_init(void)
  530. {
  531. struct proc_dir_entry *salinfo_dir; /* /proc/sal dir entry */
  532. struct proc_dir_entry **sdir = salinfo_proc_entries; /* keeps track of every entry */
  533. struct proc_dir_entry *dir, *entry;
  534. struct salinfo_data *data;
  535. int i;
  536. salinfo_dir = proc_mkdir("sal", NULL);
  537. if (!salinfo_dir)
  538. return 0;
  539. for (i=0; i < NR_SALINFO_ENTRIES; i++) {
  540. /* pass the feature bit in question as misc data */
  541. *sdir++ = proc_create_single_data(salinfo_entries[i].name, 0,
  542. salinfo_dir, proc_salinfo_show,
  543. (void *)salinfo_entries[i].feature);
  544. }
  545. for (i = 0; i < ARRAY_SIZE(salinfo_log_name); i++) {
  546. data = salinfo_data + i;
  547. data->type = i;
  548. init_waitqueue_head(&data->read_wait);
  549. dir = proc_mkdir(salinfo_log_name[i], salinfo_dir);
  550. if (!dir)
  551. continue;
  552. entry = proc_create_data("event", S_IRUSR, dir,
  553. &salinfo_event_proc_ops, data);
  554. if (!entry)
  555. continue;
  556. *sdir++ = entry;
  557. entry = proc_create_data("data", S_IRUSR | S_IWUSR, dir,
  558. &salinfo_data_proc_ops, data);
  559. if (!entry)
  560. continue;
  561. *sdir++ = entry;
  562. *sdir++ = dir;
  563. }
  564. *sdir++ = salinfo_dir;
  565. timer_setup(&salinfo_timer, salinfo_timeout, 0);
  566. salinfo_timer.expires = jiffies + SALINFO_TIMER_DELAY;
  567. add_timer(&salinfo_timer);
  568. i = cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "ia64/salinfo:online",
  569. salinfo_cpu_online, salinfo_cpu_pre_down);
  570. WARN_ON(i < 0);
  571. return 0;
  572. }
  573. module_init(salinfo_init);