Linux-2.6.12-rc2
[linux-flexiantxendom0-natty.git] / drivers / pci / hotplug / cpqphp_sysfs.c
1 /*
2  * Compaq Hot Plug Controller Driver
3  *
4  * Copyright (C) 1995,2001 Compaq Computer Corporation
5  * Copyright (C) 2001,2003 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/workqueue.h>
35 #include <linux/pci.h>
36 #include "cpqphp.h"
37
38
39 /* A few routines that create sysfs entries for the hot plug controller */
40
41 static ssize_t show_ctrl (struct device *dev, char *buf)
42 {
43         struct pci_dev *pci_dev;
44         struct controller *ctrl;
45         char * out = buf;
46         int index;
47         struct pci_resource *res;
48
49         pci_dev = container_of (dev, struct pci_dev, dev);
50         ctrl = pci_get_drvdata(pci_dev);
51
52         out += sprintf(buf, "Free resources: memory\n");
53         index = 11;
54         res = ctrl->mem_head;
55         while (res && index--) {
56                 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
57                 res = res->next;
58         }
59         out += sprintf(out, "Free resources: prefetchable memory\n");
60         index = 11;
61         res = ctrl->p_mem_head;
62         while (res && index--) {
63                 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
64                 res = res->next;
65         }
66         out += sprintf(out, "Free resources: IO\n");
67         index = 11;
68         res = ctrl->io_head;
69         while (res && index--) {
70                 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
71                 res = res->next;
72         }
73         out += sprintf(out, "Free resources: bus numbers\n");
74         index = 11;
75         res = ctrl->bus_head;
76         while (res && index--) {
77                 out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
78                 res = res->next;
79         }
80
81         return out - buf;
82 }
83 static DEVICE_ATTR (ctrl, S_IRUGO, show_ctrl, NULL);
84
85 static ssize_t show_dev (struct device *dev, char *buf)
86 {
87         struct pci_dev *pci_dev;
88         struct controller *ctrl;
89         char * out = buf;
90         int index;
91         struct pci_resource *res;
92         struct pci_func *new_slot;
93         struct slot *slot;
94
95         pci_dev = container_of (dev, struct pci_dev, dev);
96         ctrl = pci_get_drvdata(pci_dev);
97
98         slot=ctrl->slot;
99
100         while (slot) {
101                 new_slot = cpqhp_slot_find(slot->bus, slot->device, 0);
102                 if (!new_slot)
103                         break;
104                 out += sprintf(out, "assigned resources: memory\n");
105                 index = 11;
106                 res = new_slot->mem_head;
107                 while (res && index--) {
108                         out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
109                         res = res->next;
110                 }
111                 out += sprintf(out, "assigned resources: prefetchable memory\n");
112                 index = 11;
113                 res = new_slot->p_mem_head;
114                 while (res && index--) {
115                         out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
116                         res = res->next;
117                 }
118                 out += sprintf(out, "assigned resources: IO\n");
119                 index = 11;
120                 res = new_slot->io_head;
121                 while (res && index--) {
122                         out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
123                         res = res->next;
124                 }
125                 out += sprintf(out, "assigned resources: bus numbers\n");
126                 index = 11;
127                 res = new_slot->bus_head;
128                 while (res && index--) {
129                         out += sprintf(out, "start = %8.8x, length = %8.8x\n", res->base, res->length);
130                         res = res->next;
131                 }
132                 slot=slot->next;
133         }
134
135         return out - buf;
136 }
137 static DEVICE_ATTR (dev, S_IRUGO, show_dev, NULL);
138
139 void cpqhp_create_ctrl_files (struct controller *ctrl)
140 {
141         device_create_file (&ctrl->pci_dev->dev, &dev_attr_ctrl);
142         device_create_file (&ctrl->pci_dev->dev, &dev_attr_dev);
143 }