iSeries_proc.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:3k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.   * iSeries_proc.c
  3.   * Copyright (C) 2001  Kyle A. Lucke IBM Corporation
  4.   * 
  5.   * This program is free software; you can redistribute it and/or modify
  6.   * it under the terms of the GNU General Public License as published by
  7.   * the Free Software Foundation; either version 2 of the License, or
  8.   * (at your option) any later version.
  9.   * 
  10.   * This program is distributed in the hope that it will be useful,
  11.   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.   * GNU General Public License for more details.
  14.   * 
  15.   * You should have received a copy of the GNU General Public License
  16.   * along with this program; if not, write to the Free Software
  17.   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  18.   */
  19. /* Change Activity: */
  20. /* End Change Activity */
  21. #include <linux/proc_fs.h>
  22. #include <linux/spinlock.h>
  23. #ifndef _ISERIES_PROC_H
  24. #include <asm/iSeries/iSeries_proc.h>
  25. #endif
  26. static struct proc_dir_entry * iSeries_proc_root = NULL;
  27. static int iSeries_proc_initializationDone = 0;
  28. static spinlock_t iSeries_proc_lock;
  29. struct iSeries_proc_registration
  30. {
  31. struct iSeries_proc_registration *next;
  32. iSeriesProcFunction functionMember;
  33. };
  34. struct iSeries_proc_registration preallocated[16];
  35. #define MYQUEUETYPE(T) struct MYQueue##T
  36. #define MYQUEUE(T) 
  37. MYQUEUETYPE(T) 
  38. struct T *head; 
  39. struct T *tail; 
  40. }
  41. #define MYQUEUECTOR(q) do { (q)->head = NULL; (q)->tail = NULL; } while(0)
  42. #define MYQUEUEENQ(q, p) 
  43. do { 
  44. (p)->next = NULL; 
  45. if ((q)->head != NULL) { 
  46. (q)->head->next = (p); 
  47. (q)->head = (p); 
  48. } else { 
  49. (q)->tail = (q)->head = (p); 
  50. } while(0)
  51. #define MYQUEUEDEQ(q,p) 
  52. do { 
  53. (p) = (q)->tail; 
  54. if ((p) != NULL) { 
  55. (q)->tail = (p)->next; 
  56. (p)->next = NULL; 
  57. if ((q)->tail == NULL) 
  58. (q)->head = NULL; 
  59. } while(0)
  60. MYQUEUE(iSeries_proc_registration);
  61. typedef MYQUEUETYPE(iSeries_proc_registration) aQueue;
  62. aQueue iSeries_free;
  63. aQueue iSeries_queued;
  64. void iSeries_proc_early_init(void)
  65. {
  66. int i = 0;
  67. unsigned long flags;
  68. iSeries_proc_initializationDone = 0;
  69. spin_lock_init(&iSeries_proc_lock);
  70. MYQUEUECTOR(&iSeries_free);
  71. MYQUEUECTOR(&iSeries_queued);
  72. spin_lock_irqsave(&iSeries_proc_lock, flags);
  73. for (i = 0; i < 16; ++i) {
  74. MYQUEUEENQ(&iSeries_free, preallocated+i);
  75. }
  76. spin_unlock_irqrestore(&iSeries_proc_lock, flags);
  77. }
  78. void iSeries_proc_create(void)
  79. {
  80. unsigned long flags;
  81. struct iSeries_proc_registration *reg = NULL;
  82. spin_lock_irqsave(&iSeries_proc_lock, flags);
  83. printk("iSeries_proc: Creating /proc/iSeriesn");
  84. iSeries_proc_root = proc_mkdir("iSeries", 0);
  85. if (!iSeries_proc_root) return;
  86. MYQUEUEDEQ(&iSeries_queued, reg);
  87. while (reg != NULL) {
  88. (*(reg->functionMember))(iSeries_proc_root);
  89. MYQUEUEDEQ(&iSeries_queued, reg);
  90. }
  91. iSeries_proc_initializationDone = 1;
  92. spin_unlock_irqrestore(&iSeries_proc_lock, flags);
  93. }
  94. void iSeries_proc_callback(iSeriesProcFunction initFunction)
  95. {
  96. unsigned long flags;
  97. spin_lock_irqsave(&iSeries_proc_lock, flags);
  98. if (iSeries_proc_initializationDone) {
  99. (*initFunction)(iSeries_proc_root);
  100. } else {
  101. struct iSeries_proc_registration *reg = NULL;
  102. MYQUEUEDEQ(&iSeries_free, reg);
  103. if (reg != NULL) {
  104. /* printk("Registering %p in reg %pn", initFunction, reg); */
  105. reg->functionMember = initFunction;
  106. MYQUEUEENQ(&iSeries_queued, reg);
  107. } else {
  108. printk("Couldn't get a queue entryn");
  109. }
  110. }
  111. spin_unlock_irqrestore(&iSeries_proc_lock, flags);
  112. }