Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * Standard 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 | |
7 | * Copyright (C) 2003-2004 Intel Corporation | |
8 | * | |
9 | * All rights reserved. | |
10 | * | |
11 | * This program is free software; you can redistribute it and/or modify | |
12 | * it under the terms of the GNU General Public License as published by | |
13 | * the Free Software Foundation; either version 2 of the License, or (at | |
14 | * your option) any later version. | |
15 | * | |
16 | * This program is distributed in the hope that it will be useful, but | |
17 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or | |
19 | * NON INFRINGEMENT. See the GNU General Public License for more | |
20 | * details. | |
21 | * | |
22 | * You should have received a copy of the GNU General Public License | |
23 | * along with this program; if not, write to the Free Software | |
24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
25 | * | |
8cf4c195 | 26 | * Send feedback to <greg@kroah.com>,<kristen.c.accardi@intel.com> |
1da177e4 LT |
27 | * |
28 | */ | |
29 | #ifndef _SHPCHP_H | |
30 | #define _SHPCHP_H | |
31 | ||
32 | #include <linux/types.h> | |
33 | #include <linux/pci.h> | |
34 | #include <linux/delay.h> | |
1da177e4 LT |
35 | #include "pci_hotplug.h" |
36 | ||
37 | #if !defined(MODULE) | |
38 | #define MY_NAME "shpchp" | |
39 | #else | |
40 | #define MY_NAME THIS_MODULE->name | |
41 | #endif | |
42 | ||
43 | extern int shpchp_poll_mode; | |
44 | extern int shpchp_poll_time; | |
45 | extern int shpchp_debug; | |
46 | ||
47 | /*#define dbg(format, arg...) do { if (shpchp_debug) printk(KERN_DEBUG "%s: " format, MY_NAME , ## arg); } while (0)*/ | |
48 | #define dbg(format, arg...) do { if (shpchp_debug) printk("%s: " format, MY_NAME , ## arg); } while (0) | |
49 | #define err(format, arg...) printk(KERN_ERR "%s: " format, MY_NAME , ## arg) | |
50 | #define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg) | |
51 | #define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg) | |
52 | ||
1da177e4 LT |
53 | #define SLOT_MAGIC 0x67267321 |
54 | struct slot { | |
55 | u32 magic; | |
56 | struct slot *next; | |
57 | u8 bus; | |
58 | u8 device; | |
2178bfad | 59 | u16 status; |
1da177e4 LT |
60 | u32 number; |
61 | u8 is_a_board; | |
1da177e4 | 62 | u8 state; |
1da177e4 | 63 | u8 presence_save; |
2178bfad | 64 | u8 pwr_save; |
1da177e4 LT |
65 | struct timer_list task_event; |
66 | u8 hp_slot; | |
67 | struct controller *ctrl; | |
68 | struct hpc_ops *hpc_ops; | |
69 | struct hotplug_slot *hotplug_slot; | |
70 | struct list_head slot_list; | |
71 | }; | |
72 | ||
1da177e4 LT |
73 | struct event_info { |
74 | u32 event_type; | |
75 | u8 hp_slot; | |
76 | }; | |
77 | ||
78 | struct controller { | |
79 | struct controller *next; | |
80 | struct semaphore crit_sect; /* critical section semaphore */ | |
ee138334 | 81 | struct php_ctlr_state_s *hpc_ctlr_handle; /* HPC controller handle */ |
1da177e4 LT |
82 | int num_slots; /* Number of slots on ctlr */ |
83 | int slot_num_inc; /* 1 or -1 */ | |
1da177e4 LT |
84 | struct pci_dev *pci_dev; |
85 | struct pci_bus *pci_bus; | |
86 | struct event_info event_queue[10]; | |
87 | struct slot *slot; | |
88 | struct hpc_ops *hpc_ops; | |
89 | wait_queue_head_t queue; /* sleep & wake process */ | |
90 | u8 next_event; | |
1da177e4 LT |
91 | u8 bus; |
92 | u8 device; | |
93 | u8 function; | |
1da177e4 LT |
94 | u8 slot_device_offset; |
95 | u8 add_support; | |
96 | enum pci_bus_speed speed; | |
97 | u32 first_slot; /* First physical slot number */ | |
98 | u8 slot_bus; /* Bus where the slots handled by this controller sit */ | |
1da177e4 LT |
99 | }; |
100 | ||
424600f9 | 101 | struct hotplug_params { |
102 | u8 cache_line_size; | |
103 | u8 latency_timer; | |
104 | u8 enable_serr; | |
105 | u8 enable_perr; | |
106 | }; | |
107 | ||
1da177e4 LT |
108 | /* Define AMD SHPC ID */ |
109 | #define PCI_DEVICE_ID_AMD_GOLAM_7450 0x7450 | |
110 | ||
111 | #define INT_BUTTON_IGNORE 0 | |
112 | #define INT_PRESENCE_ON 1 | |
113 | #define INT_PRESENCE_OFF 2 | |
114 | #define INT_SWITCH_CLOSE 3 | |
115 | #define INT_SWITCH_OPEN 4 | |
116 | #define INT_POWER_FAULT 5 | |
117 | #define INT_POWER_FAULT_CLEAR 6 | |
118 | #define INT_BUTTON_PRESS 7 | |
119 | #define INT_BUTTON_RELEASE 8 | |
120 | #define INT_BUTTON_CANCEL 9 | |
121 | ||
122 | #define STATIC_STATE 0 | |
123 | #define BLINKINGON_STATE 1 | |
124 | #define BLINKINGOFF_STATE 2 | |
125 | #define POWERON_STATE 3 | |
126 | #define POWEROFF_STATE 4 | |
127 | ||
128 | #define PCI_TO_PCI_BRIDGE_CLASS 0x00060400 | |
129 | ||
130 | /* Error messages */ | |
131 | #define INTERLOCK_OPEN 0x00000002 | |
132 | #define ADD_NOT_SUPPORTED 0x00000003 | |
133 | #define CARD_FUNCTIONING 0x00000005 | |
134 | #define ADAPTER_NOT_SAME 0x00000006 | |
135 | #define NO_ADAPTER_PRESENT 0x00000009 | |
136 | #define NOT_ENOUGH_RESOURCES 0x0000000B | |
137 | #define DEVICE_TYPE_NOT_SUPPORTED 0x0000000C | |
138 | #define WRONG_BUS_FREQUENCY 0x0000000D | |
139 | #define POWER_FAILURE 0x0000000E | |
140 | ||
141 | #define REMOVE_NOT_SUPPORTED 0x00000003 | |
142 | ||
143 | #define DISABLE_CARD 1 | |
144 | ||
145 | /* | |
146 | * error Messages | |
147 | */ | |
148 | #define msg_initialization_err "Initialization failure, error=%d\n" | |
1da177e4 LT |
149 | #define msg_button_on "PCI slot #%d - powering on due to button press.\n" |
150 | #define msg_button_off "PCI slot #%d - powering off due to button press.\n" | |
151 | #define msg_button_cancel "PCI slot #%d - action canceled due to button press.\n" | |
1da177e4 LT |
152 | |
153 | /* sysfs functions for the hotplug controller info */ | |
154 | extern void shpchp_create_ctrl_files (struct controller *ctrl); | |
155 | ||
156 | /* controller functions */ | |
1da177e4 LT |
157 | extern int shpchp_event_start_thread(void); |
158 | extern void shpchp_event_stop_thread(void); | |
1da177e4 LT |
159 | extern int shpchp_enable_slot(struct slot *slot); |
160 | extern int shpchp_disable_slot(struct slot *slot); | |
161 | ||
162 | extern u8 shpchp_handle_attention_button(u8 hp_slot, void *inst_id); | |
163 | extern u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id); | |
164 | extern u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id); | |
165 | extern u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id); | |
166 | ||
1da177e4 | 167 | /* pci functions */ |
1da177e4 | 168 | extern int shpchp_save_config(struct controller *ctrl, int busnumber, int num_ctlr_slots, int first_device_num); |
dbd7a788 | 169 | extern int shpchp_configure_device(struct slot *p_slot); |
2178bfad | 170 | extern int shpchp_unconfigure_device(struct slot *p_slot); |
424600f9 | 171 | extern void get_hp_hw_control_from_firmware(struct pci_dev *dev); |
172 | extern void get_hp_params_from_firmware(struct pci_dev *dev, | |
173 | struct hotplug_params *hpp); | |
174 | extern int shpchprm_get_physical_slot_number(struct controller *ctrl, | |
175 | u32 *sun, u8 busnum, u8 devnum); | |
c2608a11 | 176 | extern void shpchp_remove_ctrl_files(struct controller *ctrl); |
1da177e4 LT |
177 | |
178 | ||
179 | /* Global variables */ | |
180 | extern struct controller *shpchp_ctrl_list; | |
1da177e4 | 181 | |
1da177e4 LT |
182 | struct ctrl_reg { |
183 | volatile u32 base_offset; | |
184 | volatile u32 slot_avail1; | |
185 | volatile u32 slot_avail2; | |
186 | volatile u32 slot_config; | |
187 | volatile u16 sec_bus_config; | |
188 | volatile u8 msi_ctrl; | |
189 | volatile u8 prog_interface; | |
190 | volatile u16 cmd; | |
191 | volatile u16 cmd_status; | |
192 | volatile u32 intr_loc; | |
193 | volatile u32 serr_loc; | |
194 | volatile u32 serr_intr_enable; | |
195 | volatile u32 slot1; | |
196 | volatile u32 slot2; | |
197 | volatile u32 slot3; | |
198 | volatile u32 slot4; | |
199 | volatile u32 slot5; | |
200 | volatile u32 slot6; | |
201 | volatile u32 slot7; | |
202 | volatile u32 slot8; | |
203 | volatile u32 slot9; | |
204 | volatile u32 slot10; | |
205 | volatile u32 slot11; | |
206 | volatile u32 slot12; | |
207 | } __attribute__ ((packed)); | |
208 | ||
209 | /* offsets to the controller registers based on the above structure layout */ | |
210 | enum ctrl_offsets { | |
211 | BASE_OFFSET = offsetof(struct ctrl_reg, base_offset), | |
212 | SLOT_AVAIL1 = offsetof(struct ctrl_reg, slot_avail1), | |
213 | SLOT_AVAIL2 = offsetof(struct ctrl_reg, slot_avail2), | |
214 | SLOT_CONFIG = offsetof(struct ctrl_reg, slot_config), | |
215 | SEC_BUS_CONFIG = offsetof(struct ctrl_reg, sec_bus_config), | |
216 | MSI_CTRL = offsetof(struct ctrl_reg, msi_ctrl), | |
217 | PROG_INTERFACE = offsetof(struct ctrl_reg, prog_interface), | |
218 | CMD = offsetof(struct ctrl_reg, cmd), | |
219 | CMD_STATUS = offsetof(struct ctrl_reg, cmd_status), | |
220 | INTR_LOC = offsetof(struct ctrl_reg, intr_loc), | |
221 | SERR_LOC = offsetof(struct ctrl_reg, serr_loc), | |
222 | SERR_INTR_ENABLE = offsetof(struct ctrl_reg, serr_intr_enable), | |
223 | SLOT1 = offsetof(struct ctrl_reg, slot1), | |
224 | SLOT2 = offsetof(struct ctrl_reg, slot2), | |
225 | SLOT3 = offsetof(struct ctrl_reg, slot3), | |
226 | SLOT4 = offsetof(struct ctrl_reg, slot4), | |
227 | SLOT5 = offsetof(struct ctrl_reg, slot5), | |
228 | SLOT6 = offsetof(struct ctrl_reg, slot6), | |
229 | SLOT7 = offsetof(struct ctrl_reg, slot7), | |
230 | SLOT8 = offsetof(struct ctrl_reg, slot8), | |
231 | SLOT9 = offsetof(struct ctrl_reg, slot9), | |
232 | SLOT10 = offsetof(struct ctrl_reg, slot10), | |
233 | SLOT11 = offsetof(struct ctrl_reg, slot11), | |
234 | SLOT12 = offsetof(struct ctrl_reg, slot12), | |
235 | }; | |
ee138334 | 236 | typedef u8(*php_intr_callback_t) (u8 hp_slot, void *instance_id); |
1da177e4 LT |
237 | struct php_ctlr_state_s { |
238 | struct php_ctlr_state_s *pnext; | |
239 | struct pci_dev *pci_dev; | |
240 | unsigned int irq; | |
241 | unsigned long flags; /* spinlock's */ | |
242 | u32 slot_device_offset; | |
243 | u32 num_slots; | |
244 | struct timer_list int_poll_timer; /* Added for poll event */ | |
245 | php_intr_callback_t attention_button_callback; | |
246 | php_intr_callback_t switch_change_callback; | |
247 | php_intr_callback_t presence_change_callback; | |
248 | php_intr_callback_t power_fault_callback; | |
249 | void *callback_instance_id; | |
250 | void __iomem *creg; /* Ptr to controller register space */ | |
251 | }; | |
252 | /* Inline functions */ | |
253 | ||
254 | ||
255 | /* Inline functions to check the sanity of a pointer that is passed to us */ | |
256 | static inline int slot_paranoia_check (struct slot *slot, const char *function) | |
257 | { | |
258 | if (!slot) { | |
259 | dbg("%s - slot == NULL", function); | |
260 | return -1; | |
261 | } | |
262 | if (slot->magic != SLOT_MAGIC) { | |
263 | dbg("%s - bad magic number for slot", function); | |
264 | return -1; | |
265 | } | |
266 | if (!slot->hotplug_slot) { | |
267 | dbg("%s - slot->hotplug_slot == NULL!", function); | |
268 | return -1; | |
269 | } | |
270 | return 0; | |
271 | } | |
272 | ||
273 | static inline struct slot *get_slot (struct hotplug_slot *hotplug_slot, const char *function) | |
274 | { | |
275 | struct slot *slot; | |
276 | ||
277 | if (!hotplug_slot) { | |
278 | dbg("%s - hotplug_slot == NULL\n", function); | |
279 | return NULL; | |
280 | } | |
281 | ||
282 | slot = (struct slot *)hotplug_slot->private; | |
283 | if (slot_paranoia_check (slot, function)) | |
284 | return NULL; | |
285 | return slot; | |
286 | } | |
287 | ||
288 | static inline struct slot *shpchp_find_slot (struct controller *ctrl, u8 device) | |
289 | { | |
290 | struct slot *p_slot, *tmp_slot = NULL; | |
291 | ||
292 | if (!ctrl) | |
293 | return NULL; | |
294 | ||
295 | p_slot = ctrl->slot; | |
296 | ||
1da177e4 LT |
297 | while (p_slot && (p_slot->device != device)) { |
298 | tmp_slot = p_slot; | |
299 | p_slot = p_slot->next; | |
1da177e4 LT |
300 | } |
301 | if (p_slot == NULL) { | |
302 | err("ERROR: shpchp_find_slot device=0x%x\n", device); | |
303 | p_slot = tmp_slot; | |
304 | } | |
305 | ||
306 | return (p_slot); | |
307 | } | |
308 | ||
309 | static inline int wait_for_ctrl_irq (struct controller *ctrl) | |
310 | { | |
311 | DECLARE_WAITQUEUE(wait, current); | |
312 | int retval = 0; | |
313 | ||
1da177e4 LT |
314 | add_wait_queue(&ctrl->queue, &wait); |
315 | ||
316 | if (!shpchp_poll_mode) { | |
317 | /* Sleep for up to 1 second */ | |
318 | msleep_interruptible(1000); | |
319 | } else { | |
320 | /* Sleep for up to 2 seconds */ | |
321 | msleep_interruptible(2000); | |
322 | } | |
323 | remove_wait_queue(&ctrl->queue, &wait); | |
324 | if (signal_pending(current)) | |
325 | retval = -EINTR; | |
326 | ||
1da177e4 LT |
327 | return retval; |
328 | } | |
329 | ||
1da177e4 LT |
330 | #define SLOT_NAME_SIZE 10 |
331 | ||
332 | static inline void make_slot_name(char *buffer, int buffer_size, struct slot *slot) | |
333 | { | |
1248d636 | 334 | snprintf(buffer, buffer_size, "%04d_%04d", slot->bus, slot->number); |
1da177e4 LT |
335 | } |
336 | ||
337 | enum php_ctlr_type { | |
338 | PCI, | |
339 | ISA, | |
340 | ACPI | |
341 | }; | |
342 | ||
ee138334 | 343 | int shpc_init( struct controller *ctrl, struct pci_dev *pdev); |
1da177e4 LT |
344 | |
345 | int shpc_get_ctlr_slot_config( struct controller *ctrl, | |
346 | int *num_ctlr_slots, | |
347 | int *first_device_num, | |
348 | int *physical_slot_num, | |
349 | int *updown, | |
350 | int *flags); | |
351 | ||
352 | struct hpc_ops { | |
353 | int (*power_on_slot ) (struct slot *slot); | |
354 | int (*slot_enable ) (struct slot *slot); | |
355 | int (*slot_disable ) (struct slot *slot); | |
1da177e4 LT |
356 | int (*set_bus_speed_mode) (struct slot *slot, enum pci_bus_speed speed); |
357 | int (*get_power_status) (struct slot *slot, u8 *status); | |
358 | int (*get_attention_status) (struct slot *slot, u8 *status); | |
359 | int (*set_attention_status) (struct slot *slot, u8 status); | |
360 | int (*get_latch_status) (struct slot *slot, u8 *status); | |
361 | int (*get_adapter_status) (struct slot *slot, u8 *status); | |
362 | ||
363 | int (*get_max_bus_speed) (struct slot *slot, enum pci_bus_speed *speed); | |
364 | int (*get_cur_bus_speed) (struct slot *slot, enum pci_bus_speed *speed); | |
365 | int (*get_adapter_speed) (struct slot *slot, enum pci_bus_speed *speed); | |
366 | int (*get_mode1_ECC_cap) (struct slot *slot, u8 *mode); | |
367 | int (*get_prog_int) (struct slot *slot, u8 *prog_int); | |
368 | ||
369 | int (*query_power_fault) (struct slot *slot); | |
370 | void (*green_led_on) (struct slot *slot); | |
371 | void (*green_led_off) (struct slot *slot); | |
372 | void (*green_led_blink) (struct slot *slot); | |
373 | void (*release_ctlr) (struct controller *ctrl); | |
374 | int (*check_cmd_status) (struct controller *ctrl); | |
375 | }; | |
376 | ||
377 | #endif /* _SHPCHP_H */ |