1
2
3
4
5
6
7
8
9
10
11
12
13
14
15#ifndef _PCIEHP_H
16#define _PCIEHP_H
17
18#include <linux/types.h>
19#include <linux/pci.h>
20#include <linux/pci_hotplug.h>
21#include <linux/delay.h>
22#include <linux/mutex.h>
23#include <linux/rwsem.h>
24#include <linux/workqueue.h>
25
26#include "../pcie/portdrv.h"
27
28extern bool pciehp_poll_mode;
29extern int pciehp_poll_time;
30
31
32
33
34
35#define ctrl_dbg(ctrl, format, arg...) \
36 pci_dbg(ctrl->pcie->port, format, ## arg)
37#define ctrl_err(ctrl, format, arg...) \
38 pci_err(ctrl->pcie->port, format, ## arg)
39#define ctrl_info(ctrl, format, arg...) \
40 pci_info(ctrl->pcie->port, format, ## arg)
41#define ctrl_warn(ctrl, format, arg...) \
42 pci_warn(ctrl->pcie->port, format, ## arg)
43
44#define SLOT_NAME_SIZE 10
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86struct controller {
87 struct pcie_device *pcie;
88
89 u32 slot_cap;
90 unsigned int inband_presence_disabled:1;
91
92 u16 slot_ctrl;
93 struct mutex ctrl_lock;
94 unsigned long cmd_started;
95 unsigned int cmd_busy:1;
96 wait_queue_head_t queue;
97
98 atomic_t pending_events;
99 unsigned int notification_enabled:1;
100 unsigned int power_fault_detected;
101 struct task_struct *poll_thread;
102
103 u8 state;
104 struct mutex state_lock;
105 struct delayed_work button_work;
106
107 struct hotplug_slot hotplug_slot;
108 struct rw_semaphore reset_lock;
109 unsigned int ist_running;
110 int request_result;
111 wait_queue_head_t requester;
112};
113
114
115
116
117
118
119
120
121
122
123
124
125
126#define OFF_STATE 0
127#define BLINKINGON_STATE 1
128#define BLINKINGOFF_STATE 2
129#define POWERON_STATE 3
130#define POWEROFF_STATE 4
131#define ON_STATE 5
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146#define DISABLE_SLOT (1 << 16)
147#define RERUN_ISR (1 << 17)
148
149#define ATTN_BUTTN(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_ABP)
150#define POWER_CTRL(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_PCP)
151#define MRL_SENS(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_MRLSP)
152#define ATTN_LED(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_AIP)
153#define PWR_LED(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_PIP)
154#define NO_CMD_CMPL(ctrl) ((ctrl)->slot_cap & PCI_EXP_SLTCAP_NCCS)
155#define PSN(ctrl) (((ctrl)->slot_cap & PCI_EXP_SLTCAP_PSN) >> 19)
156
157void pciehp_request(struct controller *ctrl, int action);
158void pciehp_handle_button_press(struct controller *ctrl);
159void pciehp_handle_disable_request(struct controller *ctrl);
160void pciehp_handle_presence_or_link_change(struct controller *ctrl, u32 events);
161int pciehp_configure_device(struct controller *ctrl);
162void pciehp_unconfigure_device(struct controller *ctrl, bool presence);
163void pciehp_queue_pushbutton_work(struct work_struct *work);
164struct controller *pcie_init(struct pcie_device *dev);
165int pcie_init_notification(struct controller *ctrl);
166void pcie_shutdown_notification(struct controller *ctrl);
167void pcie_clear_hotplug_events(struct controller *ctrl);
168void pcie_enable_interrupt(struct controller *ctrl);
169void pcie_disable_interrupt(struct controller *ctrl);
170int pciehp_power_on_slot(struct controller *ctrl);
171void pciehp_power_off_slot(struct controller *ctrl);
172void pciehp_get_power_status(struct controller *ctrl, u8 *status);
173
174#define INDICATOR_NOOP -1
175void pciehp_set_indicators(struct controller *ctrl, int pwr, int attn);
176
177void pciehp_get_latch_status(struct controller *ctrl, u8 *status);
178int pciehp_query_power_fault(struct controller *ctrl);
179int pciehp_card_present(struct controller *ctrl);
180int pciehp_card_present_or_link_active(struct controller *ctrl);
181int pciehp_check_link_status(struct controller *ctrl);
182int pciehp_check_link_active(struct controller *ctrl);
183void pciehp_release_ctrl(struct controller *ctrl);
184
185int pciehp_sysfs_enable_slot(struct hotplug_slot *hotplug_slot);
186int pciehp_sysfs_disable_slot(struct hotplug_slot *hotplug_slot);
187int pciehp_reset_slot(struct hotplug_slot *hotplug_slot, bool probe);
188int pciehp_get_attention_status(struct hotplug_slot *hotplug_slot, u8 *status);
189int pciehp_set_raw_indicator_status(struct hotplug_slot *h_slot, u8 status);
190int pciehp_get_raw_indicator_status(struct hotplug_slot *h_slot, u8 *status);
191
192static inline const char *slot_name(struct controller *ctrl)
193{
194 return hotplug_slot_name(&ctrl->hotplug_slot);
195}
196
197static inline struct controller *to_ctrl(struct hotplug_slot *hotplug_slot)
198{
199 return container_of(hotplug_slot, struct controller, hotplug_slot);
200}
201
202#endif
203