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
103103 * runtime pm. If true, writing ON and OFF to the vga_switcheroo debugfs
104104 * interface is a no-op so as not to interfere with runtime pm
105105 * @list: client list
106+ * @vga_dev: pci device, indicate which GPU is bound to current audio client
106107 *
107108 * 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.
109111 */
110112 struct vga_switcheroo_client {
111113 struct pci_dev *pdev;
@@ -116,6 +118,7 @@ struct vga_switcheroo_client { · 4 unmodified lines
116118 bool active;
117119 bool driver_power_control;
118120 struct list_head list;
121+ struct pci_dev *vga_dev;
119122 };
120123
121124 /*
@@ -161,9 +164,8 @@ struct vgasr_priv { · 39 unmodified lines
161164 };
162165
163166 #define ID_BIT_AUDIO 0x100
164−#define client_is_audio(c) ((c)->id & ID_BIT_AUDIO)
165−#define client_is_vga(c) ((c)->id == VGA_SWITCHEROO_UNKNOWN_ID || \
166− !client_is_audio(c))
167+#define client_is_audio(c) ((c)->id & ID_BIT_AUDIO)
168+#define client_is_vga(c) (!client_is_audio(c))
167169 #define client_id(c) ((c)->id & ~ID_BIT_AUDIO)
168170
169171 static int vga_switcheroo_debugfs_init(struct vgasr_priv *priv);
@@ -192,14 +194,29 @@ static void vga_switcheroo_enable(void) · 22 unmodified lines
192194 vgasr_priv.handler->init();
193195
194196 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)
196199 continue;
200+
197201 ret = vgasr_priv.handler->get_client_id(client->pdev);
198202 if (ret < 0)
199203 return;
200204
201205 client->id = ret;
202206 }
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+
203220 vga_switcheroo_debugfs_init(&vgasr_priv);
204221 vgasr_priv.active = true;
205222 }
@@ -272,7 +289,9 @@ EXPORT_SYMBOL(vga_switcheroo_handler_flags); · 66 unmodified lines
272289
273290 static int register_client(struct pci_dev *pdev,
274291 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,
276295 bool driver_power_control)
277296 {
278297 struct vga_switcheroo_client *client;
@@ -287,6 +306,7 @@ static int register_client(struct pci_dev *pdev, · 8 unmodified lines
287306 client->id = id;
288307 client->active = active;
289308 client->driver_power_control = driver_power_control;
309+ client->vga_dev = vga_dev;
290310
291311 mutex_lock(&vgasr_mutex);
292312 list_add_tail(&client->list, &vgasr_priv.clients);
@@ -319,7 +339,7 @@ int vga_switcheroo_register_client(struct pci_dev *pdev, · 26 unmodified lines
319339 const struct vga_switcheroo_client_ops *ops,
320340 bool driver_power_control)
321341 {
322− return register_client(pdev, ops, VGA_SWITCHEROO_UNKNOWN_ID,
342+ return register_client(pdev, ops, VGA_SWITCHEROO_UNKNOWN_ID, NULL,
323343 pdev == vga_default_device(),
324344 driver_power_control);
325345 }
@@ -329,19 +349,40 @@ EXPORT_SYMBOL(vga_switcheroo_register_client); · 3 unmodified lines
329349 * vga_switcheroo_register_audio_client - register audio client
330350 * @pdev: client pci device
331351 * @ops: client callbacks
332− * @id: client identifier
352+ * @vga_dev: pci device which is bound to current audio client
333353 *
334354 * Register audio client (audio device on a GPU). The client is assumed
335355 * to use runtime PM. Beforehand, vga_switcheroo_client_probe_defer()
336356 * shall be called to ensure that all prerequisites are met.
337357 *
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.
339360 */
340361 int vga_switcheroo_register_audio_client(struct pci_dev *pdev,
341362 const struct vga_switcheroo_client_ops *ops,
342− enum vga_switcheroo_client_id id)
363+ struct pci_dev *vga_dev)
343364 {
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);
345386 }
346387 EXPORT_SYMBOL(vga_switcheroo_register_audio_client);
347388
include/linux/vga_switcheroo.h+4−4
@@ -84,8 +84,8 @@ enum vga_switcheroo_state { · 83 unmodified lines
8484 * Client identifier. Audio clients use the same identifier & 0x100.
8585 */
8686 enum vga_switcheroo_client_id {
87− VGA_SWITCHEROO_UNKNOWN_ID = -1,
88− VGA_SWITCHEROO_IGD,
87+ VGA_SWITCHEROO_UNKNOWN_ID = 0x1000,
88+ VGA_SWITCHEROO_IGD = 0,
8989 VGA_SWITCHEROO_DIS,
9090 VGA_SWITCHEROO_MAX_CLIENTS,
9191 };
@@ -151,7 +151,7 @@ int vga_switcheroo_register_client(struct pci_dev *dev, · 59 unmodified lines
151151 bool driver_power_control);
152152 int vga_switcheroo_register_audio_client(struct pci_dev *pdev,
153153 const struct vga_switcheroo_client_ops *ops,
154− enum vga_switcheroo_client_id id);
154+ struct pci_dev *vga_dev);
155155
156156 void vga_switcheroo_client_fb_set(struct pci_dev *dev,
157157 struct fb_info *info);
@@ -180,7 +180,7 @@ static inline int vga_switcheroo_register_handler(const struct vga_switcheroo_ha · 22 unmodified lines
180180 enum vga_switcheroo_handler_flags_t handler_flags) { return 0; }
181181 static inline int vga_switcheroo_register_audio_client(struct pci_dev *pdev,
182182 const struct vga_switcheroo_client_ops *ops,
183− enum vga_switcheroo_client_id id) { return 0; }
183+ struct pci_dev *vga_dev) { return 0; }
184184 static inline void vga_switcheroo_unregister_handler(void) {}
185185 static inline enum vga_switcheroo_handler_flags_t vga_switcheroo_handler_flags(void) { return 0; }
186186 static 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
13191319 static int register_vga_switcheroo(struct azx *chip)
13201320 {
13211321 struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
1322+ struct pci_dev *p;
13221323 int err;
13231324
13241325 if (!hda->use_vga_switcheroo)
13251326 return 0;
1326− /* FIXME: currently only handling DIS controller
1327− * is there any machine with two switchable HDMI audio controllers?
1328− */
1329− err = vga_switcheroo_register_audio_client(chip->pci, &azx_vs_ops,
1330− VGA_SWITCHEROO_DIS);
1327+
1328+ p = get_bound_vga(chip->pci);
1329+ err = vga_switcheroo_register_audio_client(chip->pci, &azx_vs_ops, p);
1330+ pci_dev_put(p);
1331+
13311332 if (err < 0)
13321333 return err;
13331334 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