ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[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 #define SLOT_MAGIC      0x67267322
51 /* name size which is used for entries in pcihpfs */
52 #define SLOT_NAME_SIZE  KOBJ_NAME_LEN           /* {_SUN} */
53
54 struct acpiphp_bridge;
55 struct acpiphp_slot;
56 struct pci_resource;
57
58 /*
59  * struct slot - slot information for each *physical* slot
60  */
61 struct slot {
62         u32 magic;
63         u8 number;
64         struct hotplug_slot     *hotplug_slot;
65         struct list_head        slot_list;
66
67         struct acpiphp_slot     *acpi_slot;
68 };
69
70 /*
71  * struct pci_resource - describes pci resource (mem, pfmem, io, bus)
72  */
73 struct pci_resource {
74         struct pci_resource * next;
75         u64 base;
76         u32 length;
77 };
78
79 /**
80  * struct hpp_param - ACPI 2.0 _HPP Hot Plug Parameters
81  * @cache_line_size in DWORD
82  * @latency_timer in PCI clock
83  * @enable_SERR 0 or 1
84  * @enable_PERR 0 or 1
85  */
86 struct hpp_param {
87         u8 cache_line_size;
88         u8 latency_timer;
89         u8 enable_SERR;
90         u8 enable_PERR;
91 };
92
93
94 /**
95  * struct acpiphp_bridge - PCI bridge information
96  *
97  * for each bridge device in ACPI namespace
98  */
99 struct acpiphp_bridge {
100         struct list_head list;
101         acpi_handle handle;
102         struct acpiphp_slot *slots;
103         int type;
104         int nr_slots;
105
106         u8 seg;
107         u8 bus;
108         u8 sub;
109
110         u32 flags;
111
112         /* This bus (host bridge) or Secondary bus (PCI-to-PCI bridge) */
113         struct pci_bus *pci_bus;
114
115         /* PCI-to-PCI bridge device */
116         struct pci_dev *pci_dev;
117
118         /* ACPI 2.0 _HPP parameters */
119         struct hpp_param hpp;
120
121         spinlock_t res_lock;
122
123         /* available resources on this bus */
124         struct pci_resource *mem_head;
125         struct pci_resource *p_mem_head;
126         struct pci_resource *io_head;
127         struct pci_resource *bus_head;
128 };
129
130
131 /**
132  * struct acpiphp_slot - PCI slot information
133  *
134  * PCI slot information for each *physical* PCI slot
135  */
136 struct acpiphp_slot {
137         struct acpiphp_slot *next;
138         struct acpiphp_bridge *bridge;  /* parent */
139         struct list_head funcs;         /* one slot may have different
140                                            objects (i.e. for each function) */
141         struct semaphore crit_sect;
142
143         u32             id;             /* slot id (serial #) for hotplug core */
144         u8              device;         /* pci device# */
145
146         u32             sun;            /* ACPI _SUN (slot unique number) */
147         u32             slotno;         /* slot number relative to bridge */
148         u32             flags;          /* see below */
149 };
150
151
152 /**
153  * struct acpiphp_func - PCI function information
154  *
155  * PCI function information for each object in ACPI namespace
156  * typically 8 objects per slot (i.e. for each PCI function)
157  */
158 struct acpiphp_func {
159         struct acpiphp_slot *slot;      /* parent */
160
161         struct list_head sibling;
162         struct pci_dev *pci_dev;
163
164         acpi_handle     handle;
165
166         u8              function;       /* pci function# */
167         u32             flags;          /* see below */
168
169         /* resources used for this function */
170         struct pci_resource *mem_head;
171         struct pci_resource *p_mem_head;
172         struct pci_resource *io_head;
173         struct pci_resource *bus_head;
174 };
175
176
177 /* PCI bus bridge HID */
178 #define ACPI_PCI_HOST_HID               "PNP0A03"
179
180 /* PCI BRIDGE type */
181 #define BRIDGE_TYPE_HOST                0
182 #define BRIDGE_TYPE_P2P                 1
183
184 /* ACPI _STA method value (ignore bit 4; battery present) */
185 #define ACPI_STA_PRESENT                (0x00000001)
186 #define ACPI_STA_ENABLED                (0x00000002)
187 #define ACPI_STA_SHOW_IN_UI             (0x00000004)
188 #define ACPI_STA_FUNCTIONING            (0x00000008)
189 #define ACPI_STA_ALL                    (0x0000000f)
190
191 /* bridge flags */
192 #define BRIDGE_HAS_STA          (0x00000001)
193 #define BRIDGE_HAS_EJ0          (0x00000002)
194 #define BRIDGE_HAS_HPP          (0x00000004)
195 #define BRIDGE_HAS_PS0          (0x00000010)
196 #define BRIDGE_HAS_PS1          (0x00000020)
197 #define BRIDGE_HAS_PS2          (0x00000040)
198 #define BRIDGE_HAS_PS3          (0x00000080)
199
200 /* slot flags */
201
202 #define SLOT_POWEREDON          (0x00000001)
203 #define SLOT_ENABLED            (0x00000002)
204 #define SLOT_MULTIFUNCTION      (0x00000004)
205
206 /* function flags */
207
208 #define FUNC_HAS_STA            (0x00000001)
209 #define FUNC_HAS_EJ0            (0x00000002)
210 #define FUNC_HAS_PS0            (0x00000010)
211 #define FUNC_HAS_PS1            (0x00000020)
212 #define FUNC_HAS_PS2            (0x00000040)
213 #define FUNC_HAS_PS3            (0x00000080)
214
215 /* function prototypes */
216
217 /* acpiphp_glue.c */
218 extern int acpiphp_glue_init (void);
219 extern void acpiphp_glue_exit (void);
220 extern int acpiphp_get_num_slots (void);
221 extern struct acpiphp_slot *get_slot_from_id (int id);
222 typedef int (*acpiphp_callback)(struct acpiphp_slot *slot, void *data);
223 extern int acpiphp_for_each_slot (acpiphp_callback fn, void *data);
224
225 extern int acpiphp_check_bridge (struct acpiphp_bridge *bridge);
226 extern int acpiphp_enable_slot (struct acpiphp_slot *slot);
227 extern int acpiphp_disable_slot (struct acpiphp_slot *slot);
228 extern u8 acpiphp_get_power_status (struct acpiphp_slot *slot);
229 extern u8 acpiphp_get_attention_status (struct acpiphp_slot *slot);
230 extern u8 acpiphp_get_latch_status (struct acpiphp_slot *slot);
231 extern u8 acpiphp_get_adapter_status (struct acpiphp_slot *slot);
232 extern u32 acpiphp_get_address (struct acpiphp_slot *slot);
233
234 /* acpiphp_pci.c */
235 extern struct pci_dev *acpiphp_allocate_pcidev (struct pci_bus *pbus, int dev, int fn);
236 extern int acpiphp_configure_slot (struct acpiphp_slot *slot);
237 extern int acpiphp_configure_function (struct acpiphp_func *func);
238 extern void acpiphp_unconfigure_function (struct acpiphp_func *func);
239 extern int acpiphp_detect_pci_resource (struct acpiphp_bridge *bridge);
240 extern int acpiphp_init_func_resource (struct acpiphp_func *func);
241
242 /* acpiphp_res.c */
243 extern struct pci_resource *acpiphp_get_io_resource (struct pci_resource **head, u32 size);
244 extern struct pci_resource *acpiphp_get_max_resource (struct pci_resource **head, u32 size);
245 extern struct pci_resource *acpiphp_get_resource (struct pci_resource **head, u32 size);
246 extern struct pci_resource *acpiphp_get_resource_with_base (struct pci_resource **head, u64 base, u32 size);
247 extern int acpiphp_resource_sort_and_combine (struct pci_resource **head);
248 extern struct pci_resource *acpiphp_make_resource (u64 base, u32 length);
249 extern void acpiphp_move_resource (struct pci_resource **from, struct pci_resource **to);
250 extern void acpiphp_free_resource (struct pci_resource **res);
251 extern void acpiphp_dump_resource (struct acpiphp_bridge *bridge); /* debug */
252 extern void acpiphp_dump_func_resource (struct acpiphp_func *func); /* debug */
253
254 /* variables */
255 extern int acpiphp_debug;
256
257 #endif /* _ACPIPHP_H */