2 * Standard Hot Plug Controller Driver
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
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.
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
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.
26 * Send feedback to <greg@kroah.com>,<kristen.c.accardi@intel.com>
32 #include <linux/types.h>
33 #include <linux/pci.h>
34 #include <linux/delay.h>
35 #include <asm/semaphore.h>
37 #include "pci_hotplug.h"
40 #define MY_NAME "shpchp"
42 #define MY_NAME THIS_MODULE->name
45 extern int shpchp_poll_mode;
46 extern int shpchp_poll_time;
47 extern int shpchp_debug;
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)
56 struct pci_func *next;
66 u32 config_space[0x20];
67 struct pci_dev* pci_dev;
70 #define SLOT_MAGIC 0x67267321
84 struct timer_list task_event;
86 struct controller *ctrl;
87 struct hpc_ops *hpc_ops;
88 struct hotplug_slot *hotplug_slot;
89 struct list_head slot_list;
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 */
103 struct pci_dev *pci_dev;
104 struct pci_bus *pci_bus;
105 struct event_info event_queue[10];
107 struct hpc_ops *hpc_ops;
108 wait_queue_head_t queue; /* sleep & wake process */
115 u8 slot_device_offset;
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 */
125 /* Define AMD SHPC ID */
126 #define PCI_DEVICE_ID_AMD_GOLAM_7450 0x7450
128 #define INT_BUTTON_IGNORE 0
129 #define INT_PRESENCE_ON 1
130 #define INT_PRESENCE_OFF 2
131 #define INT_SWITCH_CLOSE 3
132 #define INT_SWITCH_OPEN 4
133 #define INT_POWER_FAULT 5
134 #define INT_POWER_FAULT_CLEAR 6
135 #define INT_BUTTON_PRESS 7
136 #define INT_BUTTON_RELEASE 8
137 #define INT_BUTTON_CANCEL 9
139 #define STATIC_STATE 0
140 #define BLINKINGON_STATE 1
141 #define BLINKINGOFF_STATE 2
142 #define POWERON_STATE 3
143 #define POWEROFF_STATE 4
145 #define PCI_TO_PCI_BRIDGE_CLASS 0x00060400
148 #define INTERLOCK_OPEN 0x00000002
149 #define ADD_NOT_SUPPORTED 0x00000003
150 #define CARD_FUNCTIONING 0x00000005
151 #define ADAPTER_NOT_SAME 0x00000006
152 #define NO_ADAPTER_PRESENT 0x00000009
153 #define NOT_ENOUGH_RESOURCES 0x0000000B
154 #define DEVICE_TYPE_NOT_SUPPORTED 0x0000000C
155 #define WRONG_BUS_FREQUENCY 0x0000000D
156 #define POWER_FAILURE 0x0000000E
158 #define REMOVE_NOT_SUPPORTED 0x00000003
160 #define DISABLE_CARD 1
165 #define msg_initialization_err "Initialization failure, error=%d\n"
166 #define msg_HPC_rev_error "Unsupported revision of the PCI hot plug controller found.\n"
167 #define msg_HPC_non_shpc "The PCI hot plug controller is not supported by this driver.\n"
168 #define msg_HPC_not_supported "This system is not supported by this version of shpcphd mdoule. Upgrade to a newer version of shpchpd\n"
169 #define msg_button_on "PCI slot #%d - powering on due to button press.\n"
170 #define msg_button_off "PCI slot #%d - powering off due to button press.\n"
171 #define msg_button_cancel "PCI slot #%d - action canceled due to button press.\n"
172 #define msg_button_ignore "PCI slot #%d - button press ignored. (action in progress...)\n"
174 /* sysfs functions for the hotplug controller info */
175 extern void shpchp_create_ctrl_files (struct controller *ctrl);
177 /* controller functions */
178 extern int shpchp_event_start_thread(void);
179 extern void shpchp_event_stop_thread(void);
180 extern struct pci_func *shpchp_slot_create(unsigned char busnumber);
181 extern struct pci_func *shpchp_slot_find(unsigned char bus, unsigned char device, unsigned char index);
182 extern int shpchp_enable_slot(struct slot *slot);
183 extern int shpchp_disable_slot(struct slot *slot);
185 extern u8 shpchp_handle_attention_button(u8 hp_slot, void *inst_id);
186 extern u8 shpchp_handle_switch_change(u8 hp_slot, void *inst_id);
187 extern u8 shpchp_handle_presence_change(u8 hp_slot, void *inst_id);
188 extern u8 shpchp_handle_power_fault(u8 hp_slot, void *inst_id);
191 extern int shpchp_save_config(struct controller *ctrl, int busnumber, int num_ctlr_slots, int first_device_num);
192 extern int shpchp_save_slot_config(struct controller *ctrl, struct pci_func * new_slot);
193 extern int shpchp_configure_device(struct slot *p_slot);
194 extern int shpchp_unconfigure_device(struct pci_func* func);
197 /* Global variables */
198 extern struct controller *shpchp_ctrl_list;
199 extern struct pci_func *shpchp_slot_list[256];
202 volatile u32 base_offset;
203 volatile u32 slot_avail1;
204 volatile u32 slot_avail2;
205 volatile u32 slot_config;
206 volatile u16 sec_bus_config;
207 volatile u8 msi_ctrl;
208 volatile u8 prog_interface;
210 volatile u16 cmd_status;
211 volatile u32 intr_loc;
212 volatile u32 serr_loc;
213 volatile u32 serr_intr_enable;
226 } __attribute__ ((packed));
228 /* offsets to the controller registers based on the above structure layout */
230 BASE_OFFSET = offsetof(struct ctrl_reg, base_offset),
231 SLOT_AVAIL1 = offsetof(struct ctrl_reg, slot_avail1),
232 SLOT_AVAIL2 = offsetof(struct ctrl_reg, slot_avail2),
233 SLOT_CONFIG = offsetof(struct ctrl_reg, slot_config),
234 SEC_BUS_CONFIG = offsetof(struct ctrl_reg, sec_bus_config),
235 MSI_CTRL = offsetof(struct ctrl_reg, msi_ctrl),
236 PROG_INTERFACE = offsetof(struct ctrl_reg, prog_interface),
237 CMD = offsetof(struct ctrl_reg, cmd),
238 CMD_STATUS = offsetof(struct ctrl_reg, cmd_status),
239 INTR_LOC = offsetof(struct ctrl_reg, intr_loc),
240 SERR_LOC = offsetof(struct ctrl_reg, serr_loc),
241 SERR_INTR_ENABLE = offsetof(struct ctrl_reg, serr_intr_enable),
242 SLOT1 = offsetof(struct ctrl_reg, slot1),
243 SLOT2 = offsetof(struct ctrl_reg, slot2),
244 SLOT3 = offsetof(struct ctrl_reg, slot3),
245 SLOT4 = offsetof(struct ctrl_reg, slot4),
246 SLOT5 = offsetof(struct ctrl_reg, slot5),
247 SLOT6 = offsetof(struct ctrl_reg, slot6),
248 SLOT7 = offsetof(struct ctrl_reg, slot7),
249 SLOT8 = offsetof(struct ctrl_reg, slot8),
250 SLOT9 = offsetof(struct ctrl_reg, slot9),
251 SLOT10 = offsetof(struct ctrl_reg, slot10),
252 SLOT11 = offsetof(struct ctrl_reg, slot11),
253 SLOT12 = offsetof(struct ctrl_reg, slot12),
255 typedef u8(*php_intr_callback_t) (unsigned int change_id, void *instance_id);
256 struct php_ctlr_state_s {
257 struct php_ctlr_state_s *pnext;
258 struct pci_dev *pci_dev;
260 unsigned long flags; /* spinlock's */
261 u32 slot_device_offset;
263 struct timer_list int_poll_timer; /* Added for poll event */
264 php_intr_callback_t attention_button_callback;
265 php_intr_callback_t switch_change_callback;
266 php_intr_callback_t presence_change_callback;
267 php_intr_callback_t power_fault_callback;
268 void *callback_instance_id;
269 void __iomem *creg; /* Ptr to controller register space */
271 /* Inline functions */
274 /* Inline functions to check the sanity of a pointer that is passed to us */
275 static inline int slot_paranoia_check (struct slot *slot, const char *function)
278 dbg("%s - slot == NULL", function);
281 if (slot->magic != SLOT_MAGIC) {
282 dbg("%s - bad magic number for slot", function);
285 if (!slot->hotplug_slot) {
286 dbg("%s - slot->hotplug_slot == NULL!", function);
292 static inline struct slot *get_slot (struct hotplug_slot *hotplug_slot, const char *function)
297 dbg("%s - hotplug_slot == NULL\n", function);
301 slot = (struct slot *)hotplug_slot->private;
302 if (slot_paranoia_check (slot, function))
307 static inline struct slot *shpchp_find_slot (struct controller *ctrl, u8 device)
309 struct slot *p_slot, *tmp_slot = NULL;
316 dbg("p_slot = %p\n", p_slot);
318 while (p_slot && (p_slot->device != device)) {
320 p_slot = p_slot->next;
321 dbg("In while loop, p_slot = %p\n", p_slot);
323 if (p_slot == NULL) {
324 err("ERROR: shpchp_find_slot device=0x%x\n", device);
331 static inline int wait_for_ctrl_irq (struct controller *ctrl)
333 DECLARE_WAITQUEUE(wait, current);
336 dbg("%s : start\n",__FUNCTION__);
338 add_wait_queue(&ctrl->queue, &wait);
340 if (!shpchp_poll_mode) {
341 /* Sleep for up to 1 second */
342 msleep_interruptible(1000);
344 /* Sleep for up to 2 seconds */
345 msleep_interruptible(2000);
347 remove_wait_queue(&ctrl->queue, &wait);
348 if (signal_pending(current))
351 dbg("%s : end\n", __FUNCTION__);
355 #define SLOT_NAME_SIZE 10
357 static inline void make_slot_name(char *buffer, int buffer_size, struct slot *slot)
359 snprintf(buffer, buffer_size, "%04d_%04d", slot->bus, slot->number);
368 int shpc_init( struct controller *ctrl, struct pci_dev *pdev,
369 php_intr_callback_t attention_button_callback,
370 php_intr_callback_t switch_change_callback,
371 php_intr_callback_t presence_change_callback,
372 php_intr_callback_t power_fault_callback);
374 int shpc_get_ctlr_slot_config( struct controller *ctrl,
376 int *first_device_num,
377 int *physical_slot_num,
382 int (*power_on_slot ) (struct slot *slot);
383 int (*slot_enable ) (struct slot *slot);
384 int (*slot_disable ) (struct slot *slot);
385 int (*enable_all_slots) (struct slot *slot);
386 int (*pwr_on_all_slots) (struct slot *slot);
387 int (*set_bus_speed_mode) (struct slot *slot, enum pci_bus_speed speed);
388 int (*get_power_status) (struct slot *slot, u8 *status);
389 int (*get_attention_status) (struct slot *slot, u8 *status);
390 int (*set_attention_status) (struct slot *slot, u8 status);
391 int (*get_latch_status) (struct slot *slot, u8 *status);
392 int (*get_adapter_status) (struct slot *slot, u8 *status);
394 int (*get_max_bus_speed) (struct slot *slot, enum pci_bus_speed *speed);
395 int (*get_cur_bus_speed) (struct slot *slot, enum pci_bus_speed *speed);
396 int (*get_adapter_speed) (struct slot *slot, enum pci_bus_speed *speed);
397 int (*get_mode1_ECC_cap) (struct slot *slot, u8 *mode);
398 int (*get_prog_int) (struct slot *slot, u8 *prog_int);
400 int (*query_power_fault) (struct slot *slot);
401 void (*green_led_on) (struct slot *slot);
402 void (*green_led_off) (struct slot *slot);
403 void (*green_led_blink) (struct slot *slot);
404 void (*release_ctlr) (struct controller *ctrl);
405 int (*check_cmd_status) (struct controller *ctrl);
408 #endif /* _SHPCHP_H */