1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * PCI Express Hot Plug Controller Driver
5 * Copyright (C) 1995,2001 Compaq Computer Corporation
6 * Copyright (C) 2001 Greg Kroah-Hartman (greg@kroah.com)
7 * Copyright (C) 2001 IBM Corp.
8 * Copyright (C) 2003-2004 Intel Corporation
10 * All rights reserved.
12 * Send feedback to <greg@kroah.com>, <kristen.c.accardi@intel.com>
18 #include <linux/types.h>
19 #include <linux/pci.h>
20 #include <linux/pci_hotplug.h>
21 #include <linux/delay.h>
22 #include <linux/sched/signal.h> /* signal_pending() */
23 #include <linux/pcieport_if.h>
24 #include <linux/mutex.h>
25 #include <linux/workqueue.h>
27 #define MY_NAME "pciehp"
29 extern bool pciehp_poll_mode
;
30 extern int pciehp_poll_time
;
31 extern bool pciehp_debug
;
33 #define dbg(format, arg...) \
36 printk(KERN_DEBUG "%s: " format, MY_NAME, ## arg); \
38 #define err(format, arg...) \
39 printk(KERN_ERR "%s: " format, MY_NAME, ## arg)
40 #define info(format, arg...) \
41 printk(KERN_INFO "%s: " format, MY_NAME, ## arg)
42 #define warn(format, arg...) \
43 printk(KERN_WARNING "%s: " format, MY_NAME, ## arg)
45 #define ctrl_dbg(ctrl, format, arg...) \
48 dev_printk(KERN_DEBUG, &ctrl->pcie->device, \
51 #define ctrl_err(ctrl, format, arg...) \
52 dev_err(&ctrl->pcie->device, format, ## arg)
53 #define ctrl_info(ctrl, format, arg...) \
54 dev_info(&ctrl->pcie->device, format, ## arg)
55 #define ctrl_warn(ctrl, format, arg...) \
56 dev_warn(&ctrl->pcie->device, format, ## arg)
58 #define SLOT_NAME_SIZE 10
61 struct controller
*ctrl
;
62 struct hotplug_slot
*hotplug_slot
;
63 struct delayed_work work
; /* work for button event */
65 struct mutex hotplug_lock
;
66 struct workqueue_struct
*wq
;
72 struct work_struct work
;
76 struct mutex ctrl_lock
; /* controller lock */
77 struct pcie_device
*pcie
; /* PCI Express port service */
79 wait_queue_head_t queue
; /* sleep & wake process */
82 struct timer_list poll_timer
;
83 unsigned long cmd_started
; /* jiffies */
84 unsigned int cmd_busy
:1;
85 unsigned int link_active_reporting
:1;
86 unsigned int notification_enabled
:1;
87 unsigned int power_fault_detected
;
90 #define INT_PRESENCE_ON 1
91 #define INT_PRESENCE_OFF 2
92 #define INT_POWER_FAULT 3
93 #define INT_BUTTON_PRESS 4
95 #define INT_LINK_DOWN 6
97 #define STATIC_STATE 0
98 #define BLINKINGON_STATE 1
99 #define BLINKINGOFF_STATE 2
100 #define POWERON_STATE 3
101 #define POWEROFF_STATE 4
103 #define ATTN_BUTTN(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_ABP)
104 #define POWER_CTRL(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_PCP)
105 #define MRL_SENS(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_MRLSP)
106 #define ATTN_LED(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_AIP)
107 #define PWR_LED(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_PIP)
108 #define HP_SUPR_RM(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_HPS)
109 #define EMI(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_EIP)
110 #define NO_CMD_CMPL(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_NCCS)
111 #define PSN(ctrl) (((ctrl)->slot_cap & PCI_EXP_SLTCAP_PSN) >> 19)
113 int pciehp_sysfs_enable_slot(struct slot
*slot
);
114 int pciehp_sysfs_disable_slot(struct slot
*slot
);
115 void pciehp_queue_interrupt_event(struct slot
*slot
, u32 event_type
);
116 int pciehp_configure_device(struct slot
*p_slot
);
117 int pciehp_unconfigure_device(struct slot
*p_slot
);
118 void pciehp_queue_pushbutton_work(struct work_struct
*work
);
119 struct controller
*pcie_init(struct pcie_device
*dev
);
120 int pcie_init_notification(struct controller
*ctrl
);
121 int pciehp_enable_slot(struct slot
*p_slot
);
122 int pciehp_disable_slot(struct slot
*p_slot
);
123 void pcie_enable_notification(struct controller
*ctrl
);
124 int pciehp_power_on_slot(struct slot
*slot
);
125 void pciehp_power_off_slot(struct slot
*slot
);
126 void pciehp_get_power_status(struct slot
*slot
, u8
*status
);
127 void pciehp_get_attention_status(struct slot
*slot
, u8
*status
);
129 void pciehp_set_attention_status(struct slot
*slot
, u8 status
);
130 void pciehp_get_latch_status(struct slot
*slot
, u8
*status
);
131 void pciehp_get_adapter_status(struct slot
*slot
, u8
*status
);
132 int pciehp_query_power_fault(struct slot
*slot
);
133 void pciehp_green_led_on(struct slot
*slot
);
134 void pciehp_green_led_off(struct slot
*slot
);
135 void pciehp_green_led_blink(struct slot
*slot
);
136 int pciehp_check_link_status(struct controller
*ctrl
);
137 bool pciehp_check_link_active(struct controller
*ctrl
);
138 void pciehp_release_ctrl(struct controller
*ctrl
);
139 int pciehp_reset_slot(struct slot
*slot
, int probe
);
141 int pciehp_set_raw_indicator_status(struct hotplug_slot
*h_slot
, u8 status
);
142 int pciehp_get_raw_indicator_status(struct hotplug_slot
*h_slot
, u8
*status
);
144 static inline const char *slot_name(struct slot
*slot
)
146 return hotplug_slot_name(slot
->hotplug_slot
);
149 #endif /* _PCIEHP_H */