import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / drivers / hotplug / cpqphp_proc.c
1 /*
2  * Compaq Hot Plug Controller Driver
3  *
4  * Copyright (C) 1995,2001 Compaq Computer Corporation
5  * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
6  * Copyright (C) 2001 IBM Corp.
7  *
8  * All rights reserved.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or (at
13  * your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful, but
16  * WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
18  * NON INFRINGEMENT.  See the GNU General Public License for more
19  * details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  *
25  * Send feedback to <greg@kroah.com>
26  *
27  */
28
29 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/kernel.h>
32 #include <linux/types.h>
33 #include <linux/proc_fs.h>
34 #include <linux/pci.h>
35 #include "cpqphp.h"
36
37
38
39 static struct proc_dir_entry *ctrl_proc_root;
40
41 /* A few routines that create proc entries for the hot plug controller */
42
43 static int read_ctrl (char *buf, char **start, off_t offset, int len, int *eof, void *data)
44 {
45         struct controller *ctrl = (struct controller *)data;
46         char * out = buf;
47         int index;
48         struct pci_resource *res;
49
50         if (offset > 0) return 0; /* no partial requests */
51         len  = 0;
52         *eof = 1;
53
54         out += sprintf(out, "hot plug ctrl Info Page\n");
55         out += sprintf(out, "bus = %d, device = %d, function = %d\n",ctrl->bus,
56                        ctrl->device, ctrl->function);
57         out += sprintf(out, "Free resources: memory\n");
58         index = 11;
59         res = ctrl->mem_head;
60         while (res && index--) {
61                 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
62                 res = res->next;
63         }
64         out += sprintf(out, "Free resources: prefetchable memory\n");
65         index = 11;
66         res = ctrl->p_mem_head;
67         while (res && index--) {
68                 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
69                 res = res->next;
70         }
71         out += sprintf(out, "Free resources: IO\n");
72         index = 11;
73         res = ctrl->io_head;
74         while (res && index--) {
75                 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
76                 res = res->next;
77         }
78         out += sprintf(out, "Free resources: bus numbers\n");
79         index = 11;
80         res = ctrl->bus_head;
81         while (res && index--) {
82                 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
83                 res = res->next;
84         }
85
86         *start = buf;
87         len = out-buf;
88
89         return len;
90 }
91
92 static int read_dev (char *buf, char **start, off_t offset, int len, int *eof, void *data)
93 {
94         struct controller *ctrl = (struct controller *)data;
95         char * out = buf;
96         int index;
97         struct pci_resource *res;
98         struct pci_func *new_slot;
99         struct slot *slot;
100
101         if (offset > 0) return 0; /* no partial requests */
102         len  = 0;
103         *eof = 1;
104
105         out += sprintf(out, "hot plug ctrl Info Page\n");
106         out += sprintf(out, "bus = %d, device = %d, function = %d\n",ctrl->bus,
107                        ctrl->device, ctrl->function);
108
109         slot=ctrl->slot;
110
111         while (slot) {
112                 new_slot = cpqhp_slot_find(slot->bus, slot->device, 0);
113                 out += sprintf(out, "assigned resources: memory\n");
114                 index = 11;
115                 res = new_slot->mem_head;
116                 while (res && index--) {
117                         out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
118                         res = res->next;
119                 }
120                 out += sprintf(out, "assigned resources: prefetchable memory\n");
121                 index = 11;
122                 res = new_slot->p_mem_head;
123                 while (res && index--) {
124                         out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
125                         res = res->next;
126                 }
127                 out += sprintf(out, "assigned resources: IO\n");
128                 index = 11;
129                 res = new_slot->io_head;
130                 while (res && index--) {
131                         out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
132                         res = res->next;
133                 }
134                 out += sprintf(out, "assigned resources: bus numbers\n");
135                 index = 11;
136                 res = new_slot->bus_head;
137                 while (res && index--) {
138                         out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
139                         res = res->next;
140                 }
141                 slot=slot->next;
142         }
143
144         *start = buf;
145         len = out-buf;
146
147         return len;
148 }
149
150 int cpqhp_proc_create_ctrl (struct controller *ctrl)
151 {
152         strcpy(ctrl->proc_name, "hpca");
153         ctrl->proc_name[3] = 'a' + ctrl->bus;
154
155         ctrl->proc_entry = create_proc_entry(ctrl->proc_name, S_IFREG | S_IRUGO, ctrl_proc_root);
156         ctrl->proc_entry->data = ctrl;
157         ctrl->proc_entry->read_proc = &read_ctrl;
158
159         strcpy(ctrl->proc_name2, "slot_a");
160         ctrl->proc_name2[5] = 'a' + ctrl->bus;
161         ctrl->proc_entry2 = create_proc_entry(ctrl->proc_name2, S_IFREG | S_IRUGO, ctrl_proc_root);
162         ctrl->proc_entry2->data = ctrl;
163         ctrl->proc_entry2->read_proc = &read_dev;
164
165         return 0;
166 }
167
168 int cpqhp_proc_remove_ctrl (struct controller *ctrl)
169 {
170         if (ctrl->proc_entry)
171                 remove_proc_entry(ctrl->proc_name, ctrl_proc_root);
172         if (ctrl->proc_entry2)
173                 remove_proc_entry(ctrl->proc_name2, ctrl_proc_root);
174
175         return 0;
176 }
177         
178 int cpqhp_proc_init_ctrl (void)
179 {
180         ctrl_proc_root = proc_mkdir("hpc", proc_root_driver);
181         if (!ctrl_proc_root)
182                 return -ENOMEM;
183         ctrl_proc_root->owner = THIS_MODULE;
184         return 0;
185 }
186
187 int cpqhp_proc_destroy_ctrl (void)
188 {
189         remove_proc_entry("hpc", proc_root_driver);
190         return 0;
191 }
192