vga_switcheroo: Introduce struct vga_switcheroo_client_ops
authorTakashi Iwai <tiwai@suse.de>
Fri, 11 May 2012 05:51:17 +0000 (07:51 +0200)
committerTakashi Iwai <tiwai@suse.de>
Sun, 13 May 2012 09:24:09 +0000 (11:24 +0200)
This changes the API as a clean-up.  Instead of passing multiple
function pointers at each time, introduce a new struct holding the
whole callback functions and pass it to the registration.

The same struct will be used for the upcoming audio client
registration, too.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
drivers/gpu/drm/i915/i915_dma.c
drivers/gpu/drm/nouveau/nouveau_state.c
drivers/gpu/drm/radeon/radeon_device.c
drivers/gpu/vga/vga_switcheroo.c
include/linux/vga_switcheroo.h

index 006ea473b57d6e460e5a4ca98913d69f633fb5d6..42d91e841629f731957370e07c16cb9214f7c734 100644 (file)
@@ -1271,6 +1271,12 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
        return can_switch;
 }
 
+static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
+       .set_gpu_state = i915_switcheroo_set_state,
+       .reprobe = NULL,
+       .can_switch = i915_switcheroo_can_switch,
+};
+
 static int i915_load_modeset_init(struct drm_device *dev)
 {
        struct drm_i915_private *dev_priv = dev->dev_private;
@@ -1293,10 +1299,7 @@ static int i915_load_modeset_init(struct drm_device *dev)
 
        intel_register_dsm_handler();
 
-       ret = vga_switcheroo_register_client(dev->pdev,
-                                            i915_switcheroo_set_state,
-                                            NULL,
-                                            i915_switcheroo_can_switch);
+       ret = vga_switcheroo_register_client(dev->pdev, &i915_switcheroo_ops);
        if (ret)
                goto cleanup_vga_client;
 
index c2a8511e855a344d515afe9a3daba8c74736f2b5..298c09b755697f791c530fc541d559ad0465ca69 100644 (file)
@@ -662,6 +662,12 @@ error:
        return ret;
 }
 
+static const struct vga_switcheroo_client_ops nouveau_switcheroo_ops = {
+       .set_gpu_state = nouveau_switcheroo_set_state,
+       .reprobe = nouveau_switcheroo_reprobe,
+       .can_switch = nouveau_switcheroo_can_switch,
+};
+
 int
 nouveau_card_init(struct drm_device *dev)
 {
@@ -670,9 +676,7 @@ nouveau_card_init(struct drm_device *dev)
        int ret, e = 0;
 
        vga_client_register(dev->pdev, dev, NULL, nouveau_vga_set_decode);
-       vga_switcheroo_register_client(dev->pdev, nouveau_switcheroo_set_state,
-                                      nouveau_switcheroo_reprobe,
-                                      nouveau_switcheroo_can_switch);
+       vga_switcheroo_register_client(dev->pdev, &nouveau_switcheroo_ops);
 
        /* Initialise internal driver API hooks */
        ret = nouveau_init_engine_ptrs(dev);
index e1bc7e96f29c2104b56932b0a39a809821ea7dae..3d41525c1bcf4a3a03846606a2f3c74d899a0429 100644 (file)
@@ -697,6 +697,11 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
        return can_switch;
 }
 
+static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
+       .set_gpu_state = radeon_switcheroo_set_state,
+       .reprobe = NULL,
+       .can_switch = radeon_switcheroo_can_switch,
+};
 
 int radeon_device_init(struct radeon_device *rdev,
                       struct drm_device *ddev,
@@ -809,10 +814,7 @@ int radeon_device_init(struct radeon_device *rdev,
        /* this will fail for cards that aren't VGA class devices, just
         * ignore it */
        vga_client_register(rdev->pdev, rdev, NULL, radeon_vga_set_decode);
-       vga_switcheroo_register_client(rdev->pdev,
-                                      radeon_switcheroo_set_state,
-                                      NULL,
-                                      radeon_switcheroo_can_switch);
+       vga_switcheroo_register_client(rdev->pdev, &radeon_switcheroo_ops);
 
        r = radeon_init(rdev);
        if (r)
index da29da6aadace0d6bdadaf777a1f23c1a0d3d4ab..a049b743cad09cc657e19678d0c02b5c49c51fef 100644 (file)
@@ -34,9 +34,7 @@ struct vga_switcheroo_client {
        struct pci_dev *pdev;
        struct fb_info *fb_info;
        int pwr_state;
-       void (*set_gpu_state)(struct pci_dev *pdev, enum vga_switcheroo_state);
-       void (*reprobe)(struct pci_dev *pdev);
-       bool (*can_switch)(struct pci_dev *pdev);
+       const struct vga_switcheroo_client_ops *ops;
        int id;
        bool active;
        struct list_head list;
@@ -109,9 +107,7 @@ static void vga_switcheroo_enable(void)
 }
 
 int vga_switcheroo_register_client(struct pci_dev *pdev,
-                                  void (*set_gpu_state)(struct pci_dev *pdev, enum vga_switcheroo_state),
-                                  void (*reprobe)(struct pci_dev *pdev),
-                                  bool (*can_switch)(struct pci_dev *pdev))
+                                  const struct vga_switcheroo_client_ops *ops)
 {
        struct vga_switcheroo_client *client;
 
@@ -121,9 +117,7 @@ int vga_switcheroo_register_client(struct pci_dev *pdev,
 
        client->pwr_state = VGA_SWITCHEROO_ON;
        client->pdev = pdev;
-       client->set_gpu_state = set_gpu_state;
-       client->reprobe = reprobe;
-       client->can_switch = can_switch;
+       client->ops = ops;
        client->id = -1;
        if (pdev == vga_default_device())
                client->active = true;
@@ -230,7 +224,7 @@ static int vga_switchon(struct vga_switcheroo_client *client)
        if (vgasr_priv.handler->power_state)
                vgasr_priv.handler->power_state(client->id, VGA_SWITCHEROO_ON);
        /* call the driver callback to turn on device */
-       client->set_gpu_state(client->pdev, VGA_SWITCHEROO_ON);
+       client->ops->set_gpu_state(client->pdev, VGA_SWITCHEROO_ON);
        client->pwr_state = VGA_SWITCHEROO_ON;
        return 0;
 }
@@ -238,7 +232,7 @@ static int vga_switchon(struct vga_switcheroo_client *client)
 static int vga_switchoff(struct vga_switcheroo_client *client)
 {
        /* call the driver callback to turn off device */
-       client->set_gpu_state(client->pdev, VGA_SWITCHEROO_OFF);
+       client->ops->set_gpu_state(client->pdev, VGA_SWITCHEROO_OFF);
        if (vgasr_priv.handler->power_state)
                vgasr_priv.handler->power_state(client->id, VGA_SWITCHEROO_OFF);
        client->pwr_state = VGA_SWITCHEROO_OFF;
@@ -284,8 +278,8 @@ static int vga_switchto_stage2(struct vga_switcheroo_client *new_client)
        if (ret)
                return ret;
 
-       if (new_client->reprobe)
-               new_client->reprobe(new_client->pdev);
+       if (new_client->ops->reprobe)
+               new_client->ops->reprobe(new_client->pdev);
 
        if (active->pwr_state == VGA_SWITCHEROO_ON)
                vga_switchoff(active);
@@ -299,7 +293,7 @@ static bool check_can_switch(void)
        struct vga_switcheroo_client *client;
 
        list_for_each_entry(client, &vgasr_priv.clients, list) {
-               if (!client->can_switch(client->pdev)) {
+               if (!client->ops->can_switch(client->pdev)) {
                        printk(KERN_ERR "vga_switcheroo: client %x refused switch\n", client->id);
                        return false;
                }
index 4b9a7f596f929cfb48a909f29ceb3422efb83b3f..3c54ebc2e529a2ececc607e927f29f4f72ed58c2 100644 (file)
@@ -28,13 +28,16 @@ struct vga_switcheroo_handler {
        int (*get_client_id)(struct pci_dev *pdev);
 };
 
+struct vga_switcheroo_client_ops {
+       void (*set_gpu_state)(struct pci_dev *dev, enum vga_switcheroo_state);
+       void (*reprobe)(struct pci_dev *dev);
+       bool (*can_switch)(struct pci_dev *dev);
+};
 
 #if defined(CONFIG_VGA_SWITCHEROO)
 void vga_switcheroo_unregister_client(struct pci_dev *dev);
 int vga_switcheroo_register_client(struct pci_dev *dev,
-                                  void (*set_gpu_state)(struct pci_dev *dev, enum vga_switcheroo_state),
-                                  void (*reprobe)(struct pci_dev *dev),
-                                  bool (*can_switch)(struct pci_dev *dev));
+                                  const struct vga_switcheroo_client_ops *ops);
 
 void vga_switcheroo_client_fb_set(struct pci_dev *dev,
                                  struct fb_info *info);
@@ -48,9 +51,7 @@ int vga_switcheroo_process_delayed_switch(void);
 
 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
 static inline int vga_switcheroo_register_client(struct pci_dev *dev,
-                                         void (*set_gpu_state)(struct pci_dev *dev, enum vga_switcheroo_state),
-                                         void (*reprobe)(struct pci_dev *dev),
-                                         bool (*can_switch)(struct pci_dev *dev)) { return 0; }
+               const struct vga_switcheroo_client_ops *ops) { return 0; }
 static inline void vga_switcheroo_client_fb_set(struct pci_dev *dev, struct fb_info *info) {}
 static inline int vga_switcheroo_register_handler(struct vga_switcheroo_handler *handler) { return 0; }
 static inline void vga_switcheroo_unregister_handler(void) {}