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 <linux/sched.h> /* signal_pending(), struct timer_list */
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)
55 #define SLOT_MAGIC 0x67267321
67 struct timer_list task_event
;
69 struct controller
*ctrl
;
70 struct hpc_ops
*hpc_ops
;
71 struct hotplug_slot
*hotplug_slot
;
72 struct list_head slot_list
;
81 struct controller
*next
;
82 struct semaphore crit_sect
; /* critical section semaphore */
83 struct php_ctlr_state_s
*hpc_ctlr_handle
; /* HPC controller handle */
84 int num_slots
; /* Number of slots on ctlr */
85 int slot_num_inc
; /* 1 or -1 */
86 struct pci_dev
*pci_dev
;
87 struct pci_bus
*pci_bus
;
88 struct event_info event_queue
[10];
90 struct hpc_ops
*hpc_ops
;
91 wait_queue_head_t queue
; /* sleep & wake process */
96 u8 slot_device_offset
;
98 enum pci_bus_speed speed
;
99 u32 first_slot
; /* First physical slot number */
100 u8 slot_bus
; /* Bus where the slots handled by this controller sit */
103 struct hotplug_params
{
110 /* Define AMD SHPC ID */
111 #define PCI_DEVICE_ID_AMD_GOLAM_7450 0x7450
113 #define INT_BUTTON_IGNORE 0
114 #define INT_PRESENCE_ON 1
115 #define INT_PRESENCE_OFF 2
116 #define INT_SWITCH_CLOSE 3
117 #define INT_SWITCH_OPEN 4
118 #define INT_POWER_FAULT 5
119 #define INT_POWER_FAULT_CLEAR 6
120 #define INT_BUTTON_PRESS 7
121 #define INT_BUTTON_RELEASE 8
122 #define INT_BUTTON_CANCEL 9
124 #define STATIC_STATE 0
125 #define BLINKINGON_STATE 1
126 #define BLINKINGOFF_STATE 2
127 #define POWERON_STATE 3
128 #define POWEROFF_STATE 4
130 #define PCI_TO_PCI_BRIDGE_CLASS 0x00060400
133 #define INTERLOCK_OPEN 0x00000002
134 #define ADD_NOT_SUPPORTED 0x00000003
135 #define CARD_FUNCTIONING 0x00000005
136 #define ADAPTER_NOT_SAME 0x00000006
137 #define NO_ADAPTER_PRESENT 0x00000009
138 #define NOT_ENOUGH_RESOURCES 0x0000000B
139 #define DEVICE_TYPE_NOT_SUPPORTED 0x0000000C
140 #define WRONG_BUS_FREQUENCY 0x0000000D
141 #define POWER_FAILURE 0x0000000E
143 #define REMOVE_NOT_SUPPORTED 0x00000003
145 #define DISABLE_CARD 1
150 #define msg_initialization_err "Initialization failure, error=%d\n"
151 #define msg_button_on "PCI slot #%d - powering on due to button press.\n"
152 #define msg_button_off "PCI slot #%d - powering off due to button press.\n"
153 #define msg_button_cancel "PCI slot #%d - action canceled due to button press.\n"
155 /* sysfs functions for the hotplug controller info */
156 extern void shpchp_create_ctrl_files (struct controller
*ctrl
);
158 /* controller functions */
159 extern int shpchp_event_start_thread(void);
160 extern void shpchp_event_stop_thread(void);
161 extern int shpchp_enable_slot(struct slot
*slot
);
162 extern int shpchp_disable_slot(struct slot
*slot
);
164 extern u8
shpchp_handle_attention_button(u8 hp_slot
, void *inst_id
);
165 extern u8
shpchp_handle_switch_change(u8 hp_slot
, void *inst_id
);
166 extern u8
shpchp_handle_presence_change(u8 hp_slot
, void *inst_id
);
167 extern u8
shpchp_handle_power_fault(u8 hp_slot
, void *inst_id
);
170 extern int shpchp_save_config(struct controller
*ctrl
, int busnumber
, int num_ctlr_slots
, int first_device_num
);
171 extern int shpchp_configure_device(struct slot
*p_slot
);
172 extern int shpchp_unconfigure_device(struct slot
*p_slot
);
173 extern void get_hp_hw_control_from_firmware(struct pci_dev
*dev
);
174 extern void get_hp_params_from_firmware(struct pci_dev
*dev
,
175 struct hotplug_params
*hpp
);
176 extern int shpchprm_get_physical_slot_number(struct controller
*ctrl
,
177 u32
*sun
, u8 busnum
, u8 devnum
);
178 extern void shpchp_remove_ctrl_files(struct controller
*ctrl
);
181 /* Global variables */
182 extern struct controller
*shpchp_ctrl_list
;
185 volatile u32 base_offset
;
186 volatile u32 slot_avail1
;
187 volatile u32 slot_avail2
;
188 volatile u32 slot_config
;
189 volatile u16 sec_bus_config
;
190 volatile u8 msi_ctrl
;
191 volatile u8 prog_interface
;
193 volatile u16 cmd_status
;
194 volatile u32 intr_loc
;
195 volatile u32 serr_loc
;
196 volatile u32 serr_intr_enable
;
209 } __attribute__ ((packed
));
211 /* offsets to the controller registers based on the above structure layout */
213 BASE_OFFSET
= offsetof(struct ctrl_reg
, base_offset
),
214 SLOT_AVAIL1
= offsetof(struct ctrl_reg
, slot_avail1
),
215 SLOT_AVAIL2
= offsetof(struct ctrl_reg
, slot_avail2
),
216 SLOT_CONFIG
= offsetof(struct ctrl_reg
, slot_config
),
217 SEC_BUS_CONFIG
= offsetof(struct ctrl_reg
, sec_bus_config
),
218 MSI_CTRL
= offsetof(struct ctrl_reg
, msi_ctrl
),
219 PROG_INTERFACE
= offsetof(struct ctrl_reg
, prog_interface
),
220 CMD
= offsetof(struct ctrl_reg
, cmd
),
221 CMD_STATUS
= offsetof(struct ctrl_reg
, cmd_status
),
222 INTR_LOC
= offsetof(struct ctrl_reg
, intr_loc
),
223 SERR_LOC
= offsetof(struct ctrl_reg
, serr_loc
),
224 SERR_INTR_ENABLE
= offsetof(struct ctrl_reg
, serr_intr_enable
),
225 SLOT1
= offsetof(struct ctrl_reg
, slot1
),
226 SLOT2
= offsetof(struct ctrl_reg
, slot2
),
227 SLOT3
= offsetof(struct ctrl_reg
, slot3
),
228 SLOT4
= offsetof(struct ctrl_reg
, slot4
),
229 SLOT5
= offsetof(struct ctrl_reg
, slot5
),
230 SLOT6
= offsetof(struct ctrl_reg
, slot6
),
231 SLOT7
= offsetof(struct ctrl_reg
, slot7
),
232 SLOT8
= offsetof(struct ctrl_reg
, slot8
),
233 SLOT9
= offsetof(struct ctrl_reg
, slot9
),
234 SLOT10
= offsetof(struct ctrl_reg
, slot10
),
235 SLOT11
= offsetof(struct ctrl_reg
, slot11
),
236 SLOT12
= offsetof(struct ctrl_reg
, slot12
),
238 typedef u8(*php_intr_callback_t
) (u8 hp_slot
, void *instance_id
);
239 struct php_ctlr_state_s
{
240 struct php_ctlr_state_s
*pnext
;
241 struct pci_dev
*pci_dev
;
243 unsigned long flags
; /* spinlock's */
244 u32 slot_device_offset
;
246 struct timer_list int_poll_timer
; /* Added for poll event */
247 php_intr_callback_t attention_button_callback
;
248 php_intr_callback_t switch_change_callback
;
249 php_intr_callback_t presence_change_callback
;
250 php_intr_callback_t power_fault_callback
;
251 void *callback_instance_id
;
252 void __iomem
*creg
; /* Ptr to controller register space */
254 /* Inline functions */
257 /* Inline functions to check the sanity of a pointer that is passed to us */
258 static inline int slot_paranoia_check (struct slot
*slot
, const char *function
)
261 dbg("%s - slot == NULL", function
);
264 if (slot
->magic
!= SLOT_MAGIC
) {
265 dbg("%s - bad magic number for slot", function
);
268 if (!slot
->hotplug_slot
) {
269 dbg("%s - slot->hotplug_slot == NULL!", function
);
275 static inline struct slot
*get_slot (struct hotplug_slot
*hotplug_slot
, const char *function
)
280 dbg("%s - hotplug_slot == NULL\n", function
);
284 slot
= (struct slot
*)hotplug_slot
->private;
285 if (slot_paranoia_check (slot
, function
))
290 static inline struct slot
*shpchp_find_slot (struct controller
*ctrl
, u8 device
)
292 struct slot
*p_slot
, *tmp_slot
= NULL
;
299 while (p_slot
&& (p_slot
->device
!= device
)) {
301 p_slot
= p_slot
->next
;
303 if (p_slot
== NULL
) {
304 err("ERROR: shpchp_find_slot device=0x%x\n", device
);
311 static inline int wait_for_ctrl_irq (struct controller
*ctrl
)
313 DECLARE_WAITQUEUE(wait
, current
);
316 add_wait_queue(&ctrl
->queue
, &wait
);
318 if (!shpchp_poll_mode
) {
319 /* Sleep for up to 1 second */
320 msleep_interruptible(1000);
322 /* Sleep for up to 2 seconds */
323 msleep_interruptible(2000);
325 remove_wait_queue(&ctrl
->queue
, &wait
);
326 if (signal_pending(current
))
332 #define SLOT_NAME_SIZE 10
334 static inline void make_slot_name(char *buffer
, int buffer_size
, struct slot
*slot
)
336 snprintf(buffer
, buffer_size
, "%04d_%04d", slot
->bus
, slot
->number
);
345 int shpc_init( struct controller
*ctrl
, struct pci_dev
*pdev
);
347 int shpc_get_ctlr_slot_config( struct controller
*ctrl
,
349 int *first_device_num
,
350 int *physical_slot_num
,
355 int (*power_on_slot
) (struct slot
*slot
);
356 int (*slot_enable
) (struct slot
*slot
);
357 int (*slot_disable
) (struct slot
*slot
);
358 int (*set_bus_speed_mode
) (struct slot
*slot
, enum pci_bus_speed speed
);
359 int (*get_power_status
) (struct slot
*slot
, u8
*status
);
360 int (*get_attention_status
) (struct slot
*slot
, u8
*status
);
361 int (*set_attention_status
) (struct slot
*slot
, u8 status
);
362 int (*get_latch_status
) (struct slot
*slot
, u8
*status
);
363 int (*get_adapter_status
) (struct slot
*slot
, u8
*status
);
365 int (*get_max_bus_speed
) (struct slot
*slot
, enum pci_bus_speed
*speed
);
366 int (*get_cur_bus_speed
) (struct slot
*slot
, enum pci_bus_speed
*speed
);
367 int (*get_adapter_speed
) (struct slot
*slot
, enum pci_bus_speed
*speed
);
368 int (*get_mode1_ECC_cap
) (struct slot
*slot
, u8
*mode
);
369 int (*get_prog_int
) (struct slot
*slot
, u8
*prog_int
);
371 int (*query_power_fault
) (struct slot
*slot
);
372 void (*green_led_on
) (struct slot
*slot
);
373 void (*green_led_off
) (struct slot
*slot
);
374 void (*green_led_blink
) (struct slot
*slot
);
375 void (*release_ctlr
) (struct controller
*ctrl
);
376 int (*check_cmd_status
) (struct controller
*ctrl
);
379 #endif /* _SHPCHP_H */