patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / pci / hotplug / acpiphp.h
1 /*
2  * ACPI PCI 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  * Copyright (C) 2002 Hiroshi Aono (h-aono@ap.jp.nec.com)
8  * Copyright (C) 2002,2003 Takayoshi Kochi (t-kochi@bq.jp.nec.com)
9  * Copyright (C) 2002,2003 NEC Corporation
10  *
11  * All rights reserved.
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or (at
16  * your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful, but
19  * WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
21  * NON INFRINGEMENT.  See the GNU General Public License for more
22  * details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27  *
28  * Send feedback to <gregkh@us.ibm.com>,
29  *                  <t-kochi@bq.jp.nec.com>
30  *
31  */
32
33 #ifndef _ACPIPHP_H
34 #define _ACPIPHP_H
35
36 #include <linux/acpi.h>
37 #include <linux/kobject.h>      /* for KOBJ_NAME_LEN */
38 #include "pci_hotplug.h"
39
40 #define dbg(format, arg...)                                     \
41         do {                                                    \
42                 if (acpiphp_debug)                              \
43                         printk(KERN_DEBUG "%s: " format,        \
44                                 MY_NAME , ## arg);              \
45         } while (0)
46 #define err(format, arg...) printk(KERN_ERR "%s: " format, MY_NAME , ## arg)
47 #define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg)
48 #define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg)
49
50 /* name size which is used for entries in pcihpfs */
51 #define SLOT_NAME_SIZE  KOBJ_NAME_LEN           /* {_SUN} */
52
53 struct acpiphp_bridge;
54 struct acpiphp_slot;
55 struct pci_resource;
56
57 /*
58  * struct slot - slot information for each *physical* slot
59  */
60 struct slot {
61         u8 number;
62         struct hotplug_slot     *hotplug_slot;
63         struct list_head        slot_list;
64
65         struct acpiphp_slot     *acpi_slot;
66 };
67
68 /*
69  * struct pci_resource - describes pci resource (mem, pfmem, io, bus)
70  */
71 struct pci_resource {
72         struct pci_resource * next;
73         u64 base;
74         u32 length;
75 };
76
77 /**
78  * struct hpp_param - ACPI 2.0 _HPP Hot Plug Parameters
79  * @cache_line_size in DWORD
80  * @latency_timer in PCI clock
81  * @enable_SERR 0 or 1
82  * @enable_PERR 0 or 1
83  */
84 struct hpp_param {
85         u8 cache_line_size;
86         u8 latency_timer;
87         u8 enable_SERR;
88         u8 enable_PERR;
89 };
90
91
92 /**
93  * struct acpiphp_bridge - PCI bridge information
94  *
95  * for each bridge device in ACPI namespace
96  */
97 struct acpiphp_bridge {
98         struct list_head list;
99         acpi_handle handle;
100         struct acpiphp_slot *slots;
101         int type;
102         int nr_slots;
103
104         u8 seg;
105         u8 bus;
106         u8 sub;
107
108         u32 flags;
109
110         /* This bus (host bridge) or Secondary bus (PCI-to-PCI bridge) */
111         struct pci_bus *pci_bus;
112
113         /* PCI-to-PCI bridge device */
114         struct pci_dev *pci_dev;
115
116         /* ACPI 2.0 _HPP parameters */
117         struct hpp_param hpp;
118
119         spinlock_t res_lock;
120
121         /* available resources on this bus */
122         struct pci_resource *mem_head;
123         struct pci_resource *p_mem_head;
124         struct pci_resource *io_head;
125         struct pci_resource *bus_head;
126 };
127
128
129 /**
130  * struct acpiphp_slot - PCI slot information
131  *
132  * PCI slot information for each *physical* PCI slot
133  */
134 struct acpiphp_slot {
135         struct acpiphp_slot *next;
136         struct acpiphp_bridge *bridge;  /* parent */
137         struct list_head funcs;         /* one slot may have different
138                                            objects (i.e. for each function) */
139         struct semaphore crit_sect;
140
141         u32             id;             /* slot id (serial #) for hotplug core */
142         u8              device;         /* pci device# */
143
144         u32             sun;            /* ACPI _SUN (slot unique number) */
145         u32             slotno;         /* slot number relative to bridge */
146         u32             flags;          /* see below */
147 };
148
149
150 /**
151  * struct acpiphp_func - PCI function information
152  *
153  * PCI function information for each object in ACPI namespace
154  * typically 8 objects per slot (i.e. for each PCI function)
155  */
156 struct acpiphp_func {
157         struct acpiphp_slot *slot;      /* parent */
158
159         struct list_head sibling;
160         struct pci_dev *pci_dev;
161
162         acpi_handle     handle;
163
164         u8              function;       /* pci function# */
165         u32             flags;          /* see below */
166
167         /* resources used for this function */
168         struct pci_resource *mem_head;
169         struct pci_resource *p_mem_head;
170         struct pci_resource *io_head;
171         struct pci_resource *bus_head;
172 };
173
174
175 /* PCI bus bridge HID */
176 #define ACPI_PCI_HOST_HID               "PNP0A03"
177
178 /* PCI BRIDGE type */
179 #define BRIDGE_TYPE_HOST                0
180 #define BRIDGE_TYPE_P2P                 1
181
182 /* ACPI _STA method value (ignore bit 4; battery present) */
183 #define ACPI_STA_PRESENT                (0x00000001)
184 #define ACPI_STA_ENABLED                (0x00000002)
185 #define ACPI_STA_SHOW_IN_UI             (0x00000004)
186 #define ACPI_STA_FUNCTIONING            (0x00000008)
187 #define ACPI_STA_ALL                    (0x0000000f)
188
189 /* bridge flags */
190 #define BRIDGE_HAS_STA          (0x00000001)
191 #define BRIDGE_HAS_EJ0          (0x00000002)
192 #define BRIDGE_HAS_HPP          (0x00000004)
193 #define BRIDGE_HAS_PS0          (0x00000010)
194 #define BRIDGE_HAS_PS1          (0x00000020)
195 #define BRIDGE_HAS_PS2          (0x00000040)
196 #define BRIDGE_HAS_PS3          (0x00000080)
197
198 /* slot flags */
199
200 #define SLOT_POWEREDON          (0x00000001)
201 #define SLOT_ENABLED            (0x00000002)
202 #define SLOT_MULTIFUNCTION      (0x00000004)
203
204 /* function flags */
205
206 #define FUNC_HAS_STA            (0x00000001)
207 #define FUNC_HAS_EJ0            (0x00000002)
208 #define FUNC_HAS_PS0            (0x00000010)
209 #define FUNC_HAS_PS1            (0x00000020)
210 #define FUNC_HAS_PS2            (0x00000040)
211 #define FUNC_HAS_PS3            (0x00000080)
212
213 /* function prototypes */
214
215 /* acpiphp_glue.c */
216 extern int acpiphp_glue_init (void);
217 extern void acpiphp_glue_exit (void);
218 extern int acpiphp_get_num_slots (void);
219 extern struct acpiphp_slot *get_slot_from_id (int id);
220 typedef int (*acpiphp_callback)(struct acpiphp_slot *slot, void *data);
221
222 extern int acpiphp_enable_slot (struct acpiphp_slot *slot);
223 extern int acpiphp_disable_slot (struct acpiphp_slot *slot);
224 extern u8 acpiphp_get_power_status (struct acpiphp_slot *slot);
225 extern u8 acpiphp_get_attention_status (struct acpiphp_slot *slot);
226 extern u8 acpiphp_get_latch_status (struct acpiphp_slot *slot);
227 extern u8 acpiphp_get_adapter_status (struct acpiphp_slot *slot);
228 extern u32 acpiphp_get_address (struct acpiphp_slot *slot);
229
230 /* acpiphp_pci.c */
231 extern struct pci_dev *acpiphp_allocate_pcidev (struct pci_bus *pbus, int dev, int fn);
232 extern int acpiphp_configure_slot (struct acpiphp_slot *slot);
233 extern int acpiphp_configure_function (struct acpiphp_func *func);
234 extern void acpiphp_unconfigure_function (struct acpiphp_func *func);
235 extern int acpiphp_detect_pci_resource (struct acpiphp_bridge *bridge);
236 extern int acpiphp_init_func_resource (struct acpiphp_func *func);
237
238 /* acpiphp_res.c */
239 extern struct pci_resource *acpiphp_get_io_resource (struct pci_resource **head, u32 size);
240 extern struct pci_resource *acpiphp_get_resource (struct pci_resource **head, u32 size);
241 extern struct pci_resource *acpiphp_get_resource_with_base (struct pci_resource **head, u64 base, u32 size);
242 extern int acpiphp_resource_sort_and_combine (struct pci_resource **head);
243 extern struct pci_resource *acpiphp_make_resource (u64 base, u32 length);
244 extern void acpiphp_move_resource (struct pci_resource **from, struct pci_resource **to);
245 extern void acpiphp_free_resource (struct pci_resource **res);
246 extern void acpiphp_dump_resource (struct acpiphp_bridge *bridge); /* debug */
247 extern void acpiphp_dump_func_resource (struct acpiphp_func *func); /* debug */
248
249 /* variables */
250 extern int acpiphp_debug;
251
252 #endif /* _ACPIPHP_H */