History

vga_switcheroo: set audio client id according to bound GPU id

On modern laptop, there are more and more platforms have two GPUs, and each of them maybe have audio codec for HDMP/DP output. For some dGPU which is no output, audio codec usually is disabled. In currect HDA audio driver, it will set all codec as VGA_SWITCHEROO_DIS, the audio which is binded to UMA will be suspended if user use debugfs to contorl power In HDA driver side, it is difficult to know which GPU the audio has binded to. So set the bound gpu pci dev to vga_switcheroo. if the audio client is not the third registration, audio id will set in vga_switcheroo enable function. if the audio client is the last registration when vga_switcheroo _ready() get true, we should get audio client id from bound GPU directly.

Jim Qu committed 8 years ago

Commit 4aaf4481 parent 9d3cce13 files · +62 −20Browse files

Unified · Split

3 files
  1. drivers/gpu/vga/vga_switcheroo.c +52 −11
  2. include/linux/vga_switcheroo.h +4 −4
  3. sound/pci/hda/hda_intel.c +6 −5
drivers/gpu/vga/vga_switcheroo.c+52−11
@@ -103,9 +103,11 @@ · 102 unmodified lines
103 * runtime pm. If true, writing ON and OFF to the vga_switcheroo debugfs103 * runtime pm. If true, writing ON and OFF to the vga_switcheroo debugfs
104 * interface is a no-op so as not to interfere with runtime pm104 * interface is a no-op so as not to interfere with runtime pm
105 * @list: client list105 * @list: client list
106 * @vga_dev: pci device, indicate which GPU is bound to current audio client
106 *107 *
107 * Registered client. A client can be either a GPU or an audio device on a GPU.108 * Registered client. A client can be either a GPU or an audio device on a GPU.
108 * For audio clients, the @fb_info and @active members are bogus.109 * For audio clients, the @fb_info and @active members are bogus. For GPU
110 * clients, the @vga_dev is bogus.
109 */111 */
110struct vga_switcheroo_client {112struct vga_switcheroo_client {
111 struct pci_dev *pdev;113 struct pci_dev *pdev;
@@ -116,6 +118,7 @@ struct vga_switcheroo_client { · 4 unmodified lines
116 bool active;118 bool active;
117 bool driver_power_control;119 bool driver_power_control;
118 struct list_head list;120 struct list_head list;
121 struct pci_dev *vga_dev;
119};122};
120 123
121/*124/*
@@ -161,9 +164,8 @@ struct vgasr_priv { · 39 unmodified lines
161};164};
162 165
163#define ID_BIT_AUDIO 0x100166#define ID_BIT_AUDIO 0x100
164#define client_is_audio(c) ((c)->id & ID_BIT_AUDIO)167#define client_is_audio(c) ((c)->id & ID_BIT_AUDIO)
165#define client_is_vga(c) ((c)->id == VGA_SWITCHEROO_UNKNOWN_ID || \168#define client_is_vga(c) (!client_is_audio(c))
166 !client_is_audio(c))
167#define client_id(c) ((c)->id & ~ID_BIT_AUDIO)169#define client_id(c) ((c)->id & ~ID_BIT_AUDIO)
168 170
169static int vga_switcheroo_debugfs_init(struct vgasr_priv *priv);171static int vga_switcheroo_debugfs_init(struct vgasr_priv *priv);
@@ -192,14 +194,29 @@ static void vga_switcheroo_enable(void) · 22 unmodified lines
192 vgasr_priv.handler->init();194 vgasr_priv.handler->init();
193 195
194 list_for_each_entry(client, &vgasr_priv.clients, list) {196 list_for_each_entry(client, &vgasr_priv.clients, list) {
195 if (client->id != VGA_SWITCHEROO_UNKNOWN_ID)197 if (!client_is_vga(client) ||
198 client_id(client) != VGA_SWITCHEROO_UNKNOWN_ID)
196 continue;199 continue;
200
197 ret = vgasr_priv.handler->get_client_id(client->pdev);201 ret = vgasr_priv.handler->get_client_id(client->pdev);
198 if (ret < 0)202 if (ret < 0)
199 return;203 return;
200 204
201 client->id = ret;205 client->id = ret;
202 }206 }
207
208 list_for_each_entry(client, &vgasr_priv.clients, list) {
209 if (!client_is_audio(client) ||
210 client_id(client) != VGA_SWITCHEROO_UNKNOWN_ID)
211 continue;
212
213 ret = vgasr_priv.handler->get_client_id(client->vga_dev);
214 if (ret < 0)
215 return;
216
217 client->id = ret | ID_BIT_AUDIO;
218 }
219
203 vga_switcheroo_debugfs_init(&vgasr_priv);220 vga_switcheroo_debugfs_init(&vgasr_priv);
204 vgasr_priv.active = true;221 vgasr_priv.active = true;
205}222}
@@ -272,7 +289,9 @@ EXPORT_SYMBOL(vga_switcheroo_handler_flags); · 66 unmodified lines
272 289
273static int register_client(struct pci_dev *pdev,290static int register_client(struct pci_dev *pdev,
274 const struct vga_switcheroo_client_ops *ops,291 const struct vga_switcheroo_client_ops *ops,
275 enum vga_switcheroo_client_id id, bool active,292 enum vga_switcheroo_client_id id,
293 struct pci_dev *vga_dev,
294 bool active,
276 bool driver_power_control)295 bool driver_power_control)
277{296{
278 struct vga_switcheroo_client *client;297 struct vga_switcheroo_client *client;
@@ -287,6 +306,7 @@ static int register_client(struct pci_dev *pdev, · 8 unmodified lines
287 client->id = id;306 client->id = id;
288 client->active = active;307 client->active = active;
289 client->driver_power_control = driver_power_control;308 client->driver_power_control = driver_power_control;
309 client->vga_dev = vga_dev;
290 310
291 mutex_lock(&vgasr_mutex);311 mutex_lock(&vgasr_mutex);
292 list_add_tail(&client->list, &vgasr_priv.clients);312 list_add_tail(&client->list, &vgasr_priv.clients);
@@ -319,7 +339,7 @@ int vga_switcheroo_register_client(struct pci_dev *pdev, · 26 unmodified lines
319 const struct vga_switcheroo_client_ops *ops,339 const struct vga_switcheroo_client_ops *ops,
320 bool driver_power_control)340 bool driver_power_control)
321{341{
322 return register_client(pdev, ops, VGA_SWITCHEROO_UNKNOWN_ID,342 return register_client(pdev, ops, VGA_SWITCHEROO_UNKNOWN_ID, NULL,
323 pdev == vga_default_device(),343 pdev == vga_default_device(),
324 driver_power_control);344 driver_power_control);
325}345}
@@ -329,19 +349,40 @@ EXPORT_SYMBOL(vga_switcheroo_register_client); · 3 unmodified lines
329 * vga_switcheroo_register_audio_client - register audio client349 * vga_switcheroo_register_audio_client - register audio client
330 * @pdev: client pci device350 * @pdev: client pci device
331 * @ops: client callbacks351 * @ops: client callbacks
332 * @id: client identifier352 * @vga_dev: pci device which is bound to current audio client
333 *353 *
334 * Register audio client (audio device on a GPU). The client is assumed354 * Register audio client (audio device on a GPU). The client is assumed
335 * to use runtime PM. Beforehand, vga_switcheroo_client_probe_defer()355 * to use runtime PM. Beforehand, vga_switcheroo_client_probe_defer()
336 * shall be called to ensure that all prerequisites are met.356 * shall be called to ensure that all prerequisites are met.
337 *357 *
338 * Return: 0 on success, -ENOMEM on memory allocation error.358 * Return: 0 on success, -ENOMEM on memory allocation error, -EINVAL on getting
359 * client id error.
339 */360 */
340int vga_switcheroo_register_audio_client(struct pci_dev *pdev,361int vga_switcheroo_register_audio_client(struct pci_dev *pdev,
341 const struct vga_switcheroo_client_ops *ops,362 const struct vga_switcheroo_client_ops *ops,
342 enum vga_switcheroo_client_id id)363 struct pci_dev *vga_dev)
343{364{
344 return register_client(pdev, ops, id | ID_BIT_AUDIO, false, true);365 enum vga_switcheroo_client_id id = VGA_SWITCHEROO_UNKNOWN_ID;
366
367 /*
368 * if vga_switcheroo has enabled, that mean two GPU clients and also
369 * handler are registered. Get audio client id from bound GPU client
370 * id directly, otherwise, set it as VGA_SWITCHEROO_UNKNOWN_ID,
371 * it will set to correct id in later when vga_switcheroo_enable()
372 * is called.
373 */
374 mutex_lock(&vgasr_mutex);
375 if (vgasr_priv.active) {
376 id = vgasr_priv.handler->get_client_id(vga_dev);
377 if (id < 0) {
378 mutex_unlock(&vgasr_mutex);
379 return -EINVAL;
380 }
381 }
382 mutex_unlock(&vgasr_mutex);
383
384 return register_client(pdev, ops, id | ID_BIT_AUDIO, vga_dev,
385 false, true);
345}386}
346EXPORT_SYMBOL(vga_switcheroo_register_audio_client);387EXPORT_SYMBOL(vga_switcheroo_register_audio_client);
347 388
include/linux/vga_switcheroo.h+4−4
@@ -84,8 +84,8 @@ enum vga_switcheroo_state { · 83 unmodified lines
84 * Client identifier. Audio clients use the same identifier & 0x100.84 * Client identifier. Audio clients use the same identifier & 0x100.
85 */85 */
86enum vga_switcheroo_client_id {86enum vga_switcheroo_client_id {
87 VGA_SWITCHEROO_UNKNOWN_ID = -1,87 VGA_SWITCHEROO_UNKNOWN_ID = 0x1000,
88 VGA_SWITCHEROO_IGD,88 VGA_SWITCHEROO_IGD = 0,
89 VGA_SWITCHEROO_DIS,89 VGA_SWITCHEROO_DIS,
90 VGA_SWITCHEROO_MAX_CLIENTS,90 VGA_SWITCHEROO_MAX_CLIENTS,
91};91};
@@ -151,7 +151,7 @@ int vga_switcheroo_register_client(struct pci_dev *dev, · 59 unmodified lines
151 bool driver_power_control);151 bool driver_power_control);
152int vga_switcheroo_register_audio_client(struct pci_dev *pdev,152int vga_switcheroo_register_audio_client(struct pci_dev *pdev,
153 const struct vga_switcheroo_client_ops *ops,153 const struct vga_switcheroo_client_ops *ops,
154 enum vga_switcheroo_client_id id);154 struct pci_dev *vga_dev);
155 155
156void vga_switcheroo_client_fb_set(struct pci_dev *dev,156void vga_switcheroo_client_fb_set(struct pci_dev *dev,
157 struct fb_info *info);157 struct fb_info *info);
@@ -180,7 +180,7 @@ static inline int vga_switcheroo_register_handler(const struct vga_switcheroo_ha · 22 unmodified lines
180 enum vga_switcheroo_handler_flags_t handler_flags) { return 0; }180 enum vga_switcheroo_handler_flags_t handler_flags) { return 0; }
181static inline int vga_switcheroo_register_audio_client(struct pci_dev *pdev,181static inline int vga_switcheroo_register_audio_client(struct pci_dev *pdev,
182 const struct vga_switcheroo_client_ops *ops,182 const struct vga_switcheroo_client_ops *ops,
183 enum vga_switcheroo_client_id id) { return 0; }183 struct pci_dev *vga_dev) { return 0; }
184static inline void vga_switcheroo_unregister_handler(void) {}184static inline void vga_switcheroo_unregister_handler(void) {}
185static inline enum vga_switcheroo_handler_flags_t vga_switcheroo_handler_flags(void) { return 0; }185static inline enum vga_switcheroo_handler_flags_t vga_switcheroo_handler_flags(void) { return 0; }
186static inline int vga_switcheroo_lock_ddc(struct pci_dev *pdev) { return -ENODEV; }186static inline int vga_switcheroo_lock_ddc(struct pci_dev *pdev) { return -ENODEV; }
sound/pci/hda/hda_intel.c+6−5
@@ -1319,15 +1319,16 @@ static const struct vga_switcheroo_client_ops azx_vs_ops = { · 1318 unmodified lines
1319static int register_vga_switcheroo(struct azx *chip)1319static int register_vga_switcheroo(struct azx *chip)
1320{1320{
1321 struct hda_intel *hda = container_of(chip, struct hda_intel, chip);1321 struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
1322 struct pci_dev *p;
1322 int err;1323 int err;
1323 1324
1324 if (!hda->use_vga_switcheroo)1325 if (!hda->use_vga_switcheroo)
1325 return 0;1326 return 0;
1326 /* FIXME: currently only handling DIS controller1327
1327 * is there any machine with two switchable HDMI audio controllers?1328 p = get_bound_vga(chip->pci);
1328 */1329 err = vga_switcheroo_register_audio_client(chip->pci, &azx_vs_ops, p);
1329 err = vga_switcheroo_register_audio_client(chip->pci, &azx_vs_ops,1330 pci_dev_put(p);
1330 VGA_SWITCHEROO_DIS);1331
1331 if (err < 0)1332 if (err < 0)
1332 return err;1333 return err;
1333 hda->vga_switcheroo_registered = 1;1334 hda->vga_switcheroo_registered = 1;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t