blob: 1b345ae81ddb4aa3a649661c220111eda70c15f5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 *
Kristen Accardi8cf4c192005-08-16 15:16:10 -070026 * Send feedback to <greg@kroah.com>,<kristen.c.accardi@intel.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 *
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>
35#include <asm/semaphore.h>
36#include <asm/io.h>
37#include "pci_hotplug.h"
38
39#if !defined(MODULE)
40 #define MY_NAME "shpchp"
41#else
42 #define MY_NAME THIS_MODULE->name
43#endif
44
45extern int shpchp_poll_mode;
46extern int shpchp_poll_time;
47extern int shpchp_debug;
48
49/*#define dbg(format, arg...) do { if (shpchp_debug) printk(KERN_DEBUG "%s: " format, MY_NAME , ## arg); } while (0)*/
50#define dbg(format, arg...) do { if (shpchp_debug) printk("%s: " format, MY_NAME , ## arg); } while (0)
51#define err(format, arg...) printk(KERN_ERR "%s: " format, MY_NAME , ## arg)
52#define info(format, arg...) printk(KERN_INFO "%s: " format, MY_NAME , ## arg)
53#define warn(format, arg...) printk(KERN_WARNING "%s: " format, MY_NAME , ## arg)
54
55struct pci_func {
56 struct pci_func *next;
57 u8 bus;
58 u8 device;
59 u8 function;
60 u8 is_a_board;
61 u16 status;
62 u8 configured;
63 u8 switch_save;
64 u8 presence_save;
65 u8 pwr_save;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 u32 config_space[0x20];
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 struct pci_dev* pci_dev;
68};
69
70#define SLOT_MAGIC 0x67267321
71struct slot {
72 u32 magic;
73 struct slot *next;
74 u8 bus;
75 u8 device;
76 u32 number;
77 u8 is_a_board;
78 u8 configured;
79 u8 state;
80 u8 switch_save;
81 u8 presence_save;
82 u32 capabilities;
83 u16 reserved2;
84 struct timer_list task_event;
85 u8 hp_slot;
86 struct controller *ctrl;
87 struct hpc_ops *hpc_ops;
88 struct hotplug_slot *hotplug_slot;
89 struct list_head slot_list;
90};
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092struct event_info {
93 u32 event_type;
94 u8 hp_slot;
95};
96
97struct controller {
98 struct controller *next;
99 struct semaphore crit_sect; /* critical section semaphore */
100 void * hpc_ctlr_handle; /* HPC controller handle */
101 int num_slots; /* Number of slots on ctlr */
102 int slot_num_inc; /* 1 or -1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 struct pci_dev *pci_dev;
104 struct pci_bus *pci_bus;
105 struct event_info event_queue[10];
106 struct slot *slot;
107 struct hpc_ops *hpc_ops;
108 wait_queue_head_t queue; /* sleep & wake process */
109 u8 next_event;
110 u8 seg;
111 u8 bus;
112 u8 device;
113 u8 function;
114 u8 rev;
115 u8 slot_device_offset;
116 u8 add_support;
117 enum pci_bus_speed speed;
118 u32 first_slot; /* First physical slot number */
119 u8 slot_bus; /* Bus where the slots handled by this controller sit */
120 u8 push_flag;
121 u16 ctlrcap;
122 u16 vendor_id;
123};
124
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -0700125struct hotplug_params {
126 u8 cache_line_size;
127 u8 latency_timer;
128 u8 enable_serr;
129 u8 enable_perr;
130};
131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132/* Define AMD SHPC ID */
133#define PCI_DEVICE_ID_AMD_GOLAM_7450 0x7450
134
135#define INT_BUTTON_IGNORE 0
136#define INT_PRESENCE_ON 1
137#define INT_PRESENCE_OFF 2
138#define INT_SWITCH_CLOSE 3
139#define INT_SWITCH_OPEN 4
140#define INT_POWER_FAULT 5
141#define INT_POWER_FAULT_CLEAR 6
142#define INT_BUTTON_PRESS 7
143#define INT_BUTTON_RELEASE 8
144#define INT_BUTTON_CANCEL 9
145
146#define STATIC_STATE 0
147#define BLINKINGON_STATE 1
148#define BLINKINGOFF_STATE 2
149#define POWERON_STATE 3
150#define POWEROFF_STATE 4
151
152#define PCI_TO_PCI_BRIDGE_CLASS 0x00060400
153
154/* Error messages */
155#define INTERLOCK_OPEN 0x00000002
156#define ADD_NOT_SUPPORTED 0x00000003
157#define CARD_FUNCTIONING 0x00000005
158#define ADAPTER_NOT_SAME 0x00000006
159#define NO_ADAPTER_PRESENT 0x00000009
160#define NOT_ENOUGH_RESOURCES 0x0000000B
161#define DEVICE_TYPE_NOT_SUPPORTED 0x0000000C
162#define WRONG_BUS_FREQUENCY 0x0000000D
163#define POWER_FAILURE 0x0000000E
164
165#define REMOVE_NOT_SUPPORTED 0x00000003
166
167#define DISABLE_CARD 1
168
169/*
170 * error Messages
171 */
172#define msg_initialization_err "Initialization failure, error=%d\n"
173#define msg_HPC_rev_error "Unsupported revision of the PCI hot plug controller found.\n"
174#define msg_HPC_non_shpc "The PCI hot plug controller is not supported by this driver.\n"
175#define msg_HPC_not_supported "This system is not supported by this version of shpcphd mdoule. Upgrade to a newer version of shpchpd\n"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176#define msg_button_on "PCI slot #%d - powering on due to button press.\n"
177#define msg_button_off "PCI slot #%d - powering off due to button press.\n"
178#define msg_button_cancel "PCI slot #%d - action canceled due to button press.\n"
179#define msg_button_ignore "PCI slot #%d - button press ignored. (action in progress...)\n"
180
181/* sysfs functions for the hotplug controller info */
182extern void shpchp_create_ctrl_files (struct controller *ctrl);
183
184/* controller functions */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185extern int shpchp_event_start_thread(void);
186extern void shpchp_event_stop_thread(void);
187extern struct pci_func *shpchp_slot_create(unsigned char busnumber);
188extern struct pci_func *shpchp_slot_find(unsigned char bus, unsigned char device, unsigned char index);
189extern int shpchp_enable_slot(struct slot *slot);
190extern int shpchp_disable_slot(struct slot *slot);
191
192extern u8 shpchp_handle_attention_button(u8 hp_slot, void *inst_id);
193extern u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id);
194extern u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id);
195extern u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id);
196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197/* pci functions */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198extern int shpchp_save_config(struct controller *ctrl, int busnumber, int num_ctlr_slots, int first_device_num);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199extern int shpchp_save_slot_config(struct controller *ctrl, struct pci_func * new_slot);
rajesh.shah@intel.comdbd7a782005-10-13 12:05:36 -0700200extern int shpchp_configure_device(struct slot *p_slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201extern int shpchp_unconfigure_device(struct pci_func* func);
rajesh.shah@intel.com424600f2005-10-13 12:05:38 -0700202extern void get_hp_hw_control_from_firmware(struct pci_dev *dev);
203extern void get_hp_params_from_firmware(struct pci_dev *dev,
204 struct hotplug_params *hpp);
205extern int shpchprm_get_physical_slot_number(struct controller *ctrl,
206 u32 *sun, u8 busnum, u8 devnum);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208
209/* Global variables */
210extern struct controller *shpchp_ctrl_list;
211extern struct pci_func *shpchp_slot_list[256];
212
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213struct ctrl_reg {
214 volatile u32 base_offset;
215 volatile u32 slot_avail1;
216 volatile u32 slot_avail2;
217 volatile u32 slot_config;
218 volatile u16 sec_bus_config;
219 volatile u8 msi_ctrl;
220 volatile u8 prog_interface;
221 volatile u16 cmd;
222 volatile u16 cmd_status;
223 volatile u32 intr_loc;
224 volatile u32 serr_loc;
225 volatile u32 serr_intr_enable;
226 volatile u32 slot1;
227 volatile u32 slot2;
228 volatile u32 slot3;
229 volatile u32 slot4;
230 volatile u32 slot5;
231 volatile u32 slot6;
232 volatile u32 slot7;
233 volatile u32 slot8;
234 volatile u32 slot9;
235 volatile u32 slot10;
236 volatile u32 slot11;
237 volatile u32 slot12;
238} __attribute__ ((packed));
239
240/* offsets to the controller registers based on the above structure layout */
241enum ctrl_offsets {
242 BASE_OFFSET = offsetof(struct ctrl_reg, base_offset),
243 SLOT_AVAIL1 = offsetof(struct ctrl_reg, slot_avail1),
244 SLOT_AVAIL2 = offsetof(struct ctrl_reg, slot_avail2),
245 SLOT_CONFIG = offsetof(struct ctrl_reg, slot_config),
246 SEC_BUS_CONFIG = offsetof(struct ctrl_reg, sec_bus_config),
247 MSI_CTRL = offsetof(struct ctrl_reg, msi_ctrl),
248 PROG_INTERFACE = offsetof(struct ctrl_reg, prog_interface),
249 CMD = offsetof(struct ctrl_reg, cmd),
250 CMD_STATUS = offsetof(struct ctrl_reg, cmd_status),
251 INTR_LOC = offsetof(struct ctrl_reg, intr_loc),
252 SERR_LOC = offsetof(struct ctrl_reg, serr_loc),
253 SERR_INTR_ENABLE = offsetof(struct ctrl_reg, serr_intr_enable),
254 SLOT1 = offsetof(struct ctrl_reg, slot1),
255 SLOT2 = offsetof(struct ctrl_reg, slot2),
256 SLOT3 = offsetof(struct ctrl_reg, slot3),
257 SLOT4 = offsetof(struct ctrl_reg, slot4),
258 SLOT5 = offsetof(struct ctrl_reg, slot5),
259 SLOT6 = offsetof(struct ctrl_reg, slot6),
260 SLOT7 = offsetof(struct ctrl_reg, slot7),
261 SLOT8 = offsetof(struct ctrl_reg, slot8),
262 SLOT9 = offsetof(struct ctrl_reg, slot9),
263 SLOT10 = offsetof(struct ctrl_reg, slot10),
264 SLOT11 = offsetof(struct ctrl_reg, slot11),
265 SLOT12 = offsetof(struct ctrl_reg, slot12),
266};
267typedef u8(*php_intr_callback_t) (unsigned int change_id, void *instance_id);
268struct php_ctlr_state_s {
269 struct php_ctlr_state_s *pnext;
270 struct pci_dev *pci_dev;
271 unsigned int irq;
272 unsigned long flags; /* spinlock's */
273 u32 slot_device_offset;
274 u32 num_slots;
275 struct timer_list int_poll_timer; /* Added for poll event */
276 php_intr_callback_t attention_button_callback;
277 php_intr_callback_t switch_change_callback;
278 php_intr_callback_t presence_change_callback;
279 php_intr_callback_t power_fault_callback;
280 void *callback_instance_id;
281 void __iomem *creg; /* Ptr to controller register space */
282};
283/* Inline functions */
284
285
286/* Inline functions to check the sanity of a pointer that is passed to us */
287static inline int slot_paranoia_check (struct slot *slot, const char *function)
288{
289 if (!slot) {
290 dbg("%s - slot == NULL", function);
291 return -1;
292 }
293 if (slot->magic != SLOT_MAGIC) {
294 dbg("%s - bad magic number for slot", function);
295 return -1;
296 }
297 if (!slot->hotplug_slot) {
298 dbg("%s - slot->hotplug_slot == NULL!", function);
299 return -1;
300 }
301 return 0;
302}
303
304static inline struct slot *get_slot (struct hotplug_slot *hotplug_slot, const char *function)
305{
306 struct slot *slot;
307
308 if (!hotplug_slot) {
309 dbg("%s - hotplug_slot == NULL\n", function);
310 return NULL;
311 }
312
313 slot = (struct slot *)hotplug_slot->private;
314 if (slot_paranoia_check (slot, function))
315 return NULL;
316 return slot;
317}
318
319static inline struct slot *shpchp_find_slot (struct controller *ctrl, u8 device)
320{
321 struct slot *p_slot, *tmp_slot = NULL;
322
323 if (!ctrl)
324 return NULL;
325
326 p_slot = ctrl->slot;
327
328 dbg("p_slot = %p\n", p_slot);
329
330 while (p_slot && (p_slot->device != device)) {
331 tmp_slot = p_slot;
332 p_slot = p_slot->next;
333 dbg("In while loop, p_slot = %p\n", p_slot);
334 }
335 if (p_slot == NULL) {
336 err("ERROR: shpchp_find_slot device=0x%x\n", device);
337 p_slot = tmp_slot;
338 }
339
340 return (p_slot);
341}
342
343static inline int wait_for_ctrl_irq (struct controller *ctrl)
344{
345 DECLARE_WAITQUEUE(wait, current);
346 int retval = 0;
347
348 dbg("%s : start\n",__FUNCTION__);
349
350 add_wait_queue(&ctrl->queue, &wait);
351
352 if (!shpchp_poll_mode) {
353 /* Sleep for up to 1 second */
354 msleep_interruptible(1000);
355 } else {
356 /* Sleep for up to 2 seconds */
357 msleep_interruptible(2000);
358 }
359 remove_wait_queue(&ctrl->queue, &wait);
360 if (signal_pending(current))
361 retval = -EINTR;
362
363 dbg("%s : end\n", __FUNCTION__);
364 return retval;
365}
366
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367#define SLOT_NAME_SIZE 10
368
369static inline void make_slot_name(char *buffer, int buffer_size, struct slot *slot)
370{
Kristen Accardi1248d632005-08-05 12:16:06 -0700371 snprintf(buffer, buffer_size, "%04d_%04d", slot->bus, slot->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372}
373
374enum php_ctlr_type {
375 PCI,
376 ISA,
377 ACPI
378};
379
380int shpc_init( struct controller *ctrl, struct pci_dev *pdev,
381 php_intr_callback_t attention_button_callback,
382 php_intr_callback_t switch_change_callback,
383 php_intr_callback_t presence_change_callback,
384 php_intr_callback_t power_fault_callback);
385
386int shpc_get_ctlr_slot_config( struct controller *ctrl,
387 int *num_ctlr_slots,
388 int *first_device_num,
389 int *physical_slot_num,
390 int *updown,
391 int *flags);
392
393struct hpc_ops {
394 int (*power_on_slot ) (struct slot *slot);
395 int (*slot_enable ) (struct slot *slot);
396 int (*slot_disable ) (struct slot *slot);
397 int (*enable_all_slots) (struct slot *slot);
398 int (*pwr_on_all_slots) (struct slot *slot);
399 int (*set_bus_speed_mode) (struct slot *slot, enum pci_bus_speed speed);
400 int (*get_power_status) (struct slot *slot, u8 *status);
401 int (*get_attention_status) (struct slot *slot, u8 *status);
402 int (*set_attention_status) (struct slot *slot, u8 status);
403 int (*get_latch_status) (struct slot *slot, u8 *status);
404 int (*get_adapter_status) (struct slot *slot, u8 *status);
405
406 int (*get_max_bus_speed) (struct slot *slot, enum pci_bus_speed *speed);
407 int (*get_cur_bus_speed) (struct slot *slot, enum pci_bus_speed *speed);
408 int (*get_adapter_speed) (struct slot *slot, enum pci_bus_speed *speed);
409 int (*get_mode1_ECC_cap) (struct slot *slot, u8 *mode);
410 int (*get_prog_int) (struct slot *slot, u8 *prog_int);
411
412 int (*query_power_fault) (struct slot *slot);
413 void (*green_led_on) (struct slot *slot);
414 void (*green_led_off) (struct slot *slot);
415 void (*green_led_blink) (struct slot *slot);
416 void (*release_ctlr) (struct controller *ctrl);
417 int (*check_cmd_status) (struct controller *ctrl);
418};
419
420#endif /* _SHPCHP_H */