Commit 448359c1 authored by Ben Skeggs's avatar Ben Skeggs Committed by Danilo Krummrich

drm/nouveau: replace drm_device* with nouveau_drm* as dev drvdata

We almost always want to cast the pointer from dev_get_drvdata() to
'struct nouveau_drm *', so just directly store that pointer instead,
simplifying callers, and fixing some clumsy naming of dev/drm_dev
variables at the same time.
Signed-off-by: default avatarBen Skeggs <bskeggs@nvidia.com>
Signed-off-by: default avatarDanilo Krummrich <dakr@kernel.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20240726043828.58966-4-bskeggs@nvidia.com
parent 961ae5f9
...@@ -593,8 +593,7 @@ static int ...@@ -593,8 +593,7 @@ static int
nv50_audio_component_get_eld(struct device *kdev, int port, int dev_id, nv50_audio_component_get_eld(struct device *kdev, int port, int dev_id,
bool *enabled, unsigned char *buf, int max_bytes) bool *enabled, unsigned char *buf, int max_bytes)
{ {
struct drm_device *drm_dev = dev_get_drvdata(kdev); struct nouveau_drm *drm = dev_get_drvdata(kdev);
struct nouveau_drm *drm = nouveau_drm(drm_dev);
struct drm_encoder *encoder; struct drm_encoder *encoder;
struct nouveau_encoder *nv_encoder; struct nouveau_encoder *nv_encoder;
struct nouveau_crtc *nv_crtc; struct nouveau_crtc *nv_crtc;
...@@ -639,18 +638,17 @@ static int ...@@ -639,18 +638,17 @@ static int
nv50_audio_component_bind(struct device *kdev, struct device *hda_kdev, nv50_audio_component_bind(struct device *kdev, struct device *hda_kdev,
void *data) void *data)
{ {
struct drm_device *drm_dev = dev_get_drvdata(kdev); struct nouveau_drm *drm = dev_get_drvdata(kdev);
struct nouveau_drm *drm = nouveau_drm(drm_dev);
struct drm_audio_component *acomp = data; struct drm_audio_component *acomp = data;
if (WARN_ON(!device_link_add(hda_kdev, kdev, DL_FLAG_STATELESS))) if (WARN_ON(!device_link_add(hda_kdev, kdev, DL_FLAG_STATELESS)))
return -ENOMEM; return -ENOMEM;
drm_modeset_lock_all(drm_dev); drm_modeset_lock_all(drm->dev);
acomp->ops = &nv50_audio_component_ops; acomp->ops = &nv50_audio_component_ops;
acomp->dev = kdev; acomp->dev = kdev;
drm->audio.component = acomp; drm->audio.component = acomp;
drm_modeset_unlock_all(drm_dev); drm_modeset_unlock_all(drm->dev);
return 0; return 0;
} }
...@@ -658,15 +656,14 @@ static void ...@@ -658,15 +656,14 @@ static void
nv50_audio_component_unbind(struct device *kdev, struct device *hda_kdev, nv50_audio_component_unbind(struct device *kdev, struct device *hda_kdev,
void *data) void *data)
{ {
struct drm_device *drm_dev = dev_get_drvdata(kdev); struct nouveau_drm *drm = dev_get_drvdata(kdev);
struct nouveau_drm *drm = nouveau_drm(drm_dev);
struct drm_audio_component *acomp = data; struct drm_audio_component *acomp = data;
drm_modeset_lock_all(drm_dev); drm_modeset_lock_all(drm->dev);
drm->audio.component = NULL; drm->audio.component = NULL;
acomp->ops = NULL; acomp->ops = NULL;
acomp->dev = NULL; acomp->dev = NULL;
drm_modeset_unlock_all(drm_dev); drm_modeset_unlock_all(drm->dev);
} }
static const struct component_ops nv50_audio_component_bind_ops = { static const struct component_ops nv50_audio_component_bind_ops = {
......
...@@ -446,10 +446,8 @@ static struct nouveau_drm_prop_enum_list dither_depth[] = { ...@@ -446,10 +446,8 @@ static struct nouveau_drm_prop_enum_list dither_depth[] = {
} while(0) } while(0)
void void
nouveau_display_hpd_resume(struct drm_device *dev) nouveau_display_hpd_resume(struct nouveau_drm *drm)
{ {
struct nouveau_drm *drm = nouveau_drm(dev);
spin_lock_irq(&drm->hpd_lock); spin_lock_irq(&drm->hpd_lock);
drm->hpd_pending = ~0; drm->hpd_pending = ~0;
spin_unlock_irq(&drm->hpd_lock); spin_unlock_irq(&drm->hpd_lock);
......
...@@ -45,7 +45,7 @@ nouveau_display(struct drm_device *dev) ...@@ -45,7 +45,7 @@ nouveau_display(struct drm_device *dev)
int nouveau_display_create(struct drm_device *dev); int nouveau_display_create(struct drm_device *dev);
void nouveau_display_destroy(struct drm_device *dev); void nouveau_display_destroy(struct drm_device *dev);
int nouveau_display_init(struct drm_device *dev, bool resume, bool runtime); int nouveau_display_init(struct drm_device *dev, bool resume, bool runtime);
void nouveau_display_hpd_resume(struct drm_device *dev); void nouveau_display_hpd_resume(struct nouveau_drm *);
void nouveau_display_fini(struct drm_device *dev, bool suspend, bool runtime); void nouveau_display_fini(struct drm_device *dev, bool suspend, bool runtime);
int nouveau_display_suspend(struct drm_device *dev, bool runtime); int nouveau_display_suspend(struct drm_device *dev, bool runtime);
void nouveau_display_resume(struct drm_device *dev, bool runtime); void nouveau_display_resume(struct drm_device *dev, bool runtime);
......
...@@ -579,10 +579,10 @@ nouveau_parent = { ...@@ -579,10 +579,10 @@ nouveau_parent = {
}; };
static void static void
nouveau_drm_device_fini(struct drm_device *dev) nouveau_drm_device_fini(struct nouveau_drm *drm)
{ {
struct drm_device *dev = drm->dev;
struct nouveau_cli *cli, *temp_cli; struct nouveau_cli *cli, *temp_cli;
struct nouveau_drm *drm = nouveau_drm(dev);
if (nouveau_pmops_runtime()) { if (nouveau_pmops_runtime()) {
pm_runtime_get_sync(dev->dev); pm_runtime_get_sync(dev->dev);
...@@ -707,7 +707,7 @@ nouveau_drm_device_init(struct nouveau_drm *drm) ...@@ -707,7 +707,7 @@ nouveau_drm_device_init(struct nouveau_drm *drm)
ret = drm_dev_register(drm->dev, 0); ret = drm_dev_register(drm->dev, 0);
if (ret) { if (ret) {
nouveau_drm_device_fini(drm->dev); nouveau_drm_device_fini(drm);
return ret; return ret;
} }
...@@ -758,7 +758,7 @@ nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *paren ...@@ -758,7 +758,7 @@ nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *paren
} }
drm->dev->dev_private = drm; drm->dev->dev_private = drm;
dev_set_drvdata(parent, drm->dev); dev_set_drvdata(parent, drm);
done: done:
if (ret) { if (ret) {
...@@ -811,8 +811,7 @@ nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *paren ...@@ -811,8 +811,7 @@ nouveau_drm_device_new(const struct drm_driver *drm_driver, struct device *paren
static void quirk_broken_nv_runpm(struct pci_dev *pdev) static void quirk_broken_nv_runpm(struct pci_dev *pdev)
{ {
struct drm_device *dev = pci_get_drvdata(pdev); struct nouveau_drm *drm = pci_get_drvdata(pdev);
struct nouveau_drm *drm = nouveau_drm(dev);
struct pci_dev *bridge = pci_upstream_bridge(pdev); struct pci_dev *bridge = pci_upstream_bridge(pdev);
if (!bridge || bridge->vendor != PCI_VENDOR_ID_INTEL) if (!bridge || bridge->vendor != PCI_VENDOR_ID_INTEL)
...@@ -894,18 +893,17 @@ static int nouveau_drm_probe(struct pci_dev *pdev, ...@@ -894,18 +893,17 @@ static int nouveau_drm_probe(struct pci_dev *pdev,
} }
void void
nouveau_drm_device_remove(struct drm_device *dev) nouveau_drm_device_remove(struct nouveau_drm *drm)
{ {
struct nouveau_drm *drm = nouveau_drm(dev);
struct nvkm_client *client; struct nvkm_client *client;
struct nvkm_device *device; struct nvkm_device *device;
drm_dev_unplug(dev); drm_dev_unplug(drm->dev);
client = nvxx_client(&drm->client.base); client = nvxx_client(&drm->client.base);
device = nvkm_device_find(client->device); device = nvkm_device_find(client->device);
nouveau_drm_device_fini(dev); nouveau_drm_device_fini(drm);
nouveau_drm_device_del(drm); nouveau_drm_device_del(drm);
nvkm_device_del(&device); nvkm_device_del(&device);
} }
...@@ -913,20 +911,19 @@ nouveau_drm_device_remove(struct drm_device *dev) ...@@ -913,20 +911,19 @@ nouveau_drm_device_remove(struct drm_device *dev)
static void static void
nouveau_drm_remove(struct pci_dev *pdev) nouveau_drm_remove(struct pci_dev *pdev)
{ {
struct drm_device *dev = pci_get_drvdata(pdev); struct nouveau_drm *drm = pci_get_drvdata(pdev);
struct nouveau_drm *drm = nouveau_drm(dev);
/* revert our workaround */ /* revert our workaround */
if (drm->old_pm_cap) if (drm->old_pm_cap)
pdev->pm_cap = drm->old_pm_cap; pdev->pm_cap = drm->old_pm_cap;
nouveau_drm_device_remove(dev); nouveau_drm_device_remove(drm);
pci_disable_device(pdev); pci_disable_device(pdev);
} }
static int static int
nouveau_do_suspend(struct drm_device *dev, bool runtime) nouveau_do_suspend(struct nouveau_drm *drm, bool runtime)
{ {
struct nouveau_drm *drm = nouveau_drm(dev); struct drm_device *dev = drm->dev;
struct ttm_resource_manager *man; struct ttm_resource_manager *man;
int ret; int ret;
...@@ -987,10 +984,10 @@ nouveau_do_suspend(struct drm_device *dev, bool runtime) ...@@ -987,10 +984,10 @@ nouveau_do_suspend(struct drm_device *dev, bool runtime)
} }
static int static int
nouveau_do_resume(struct drm_device *dev, bool runtime) nouveau_do_resume(struct nouveau_drm *drm, bool runtime)
{ {
struct drm_device *dev = drm->dev;
int ret = 0; int ret = 0;
struct nouveau_drm *drm = nouveau_drm(dev);
NV_DEBUG(drm, "resuming object tree...\n"); NV_DEBUG(drm, "resuming object tree...\n");
ret = nvif_client_resume(&drm->master.base); ret = nvif_client_resume(&drm->master.base);
...@@ -1020,14 +1017,14 @@ int ...@@ -1020,14 +1017,14 @@ int
nouveau_pmops_suspend(struct device *dev) nouveau_pmops_suspend(struct device *dev)
{ {
struct pci_dev *pdev = to_pci_dev(dev); struct pci_dev *pdev = to_pci_dev(dev);
struct drm_device *drm_dev = pci_get_drvdata(pdev); struct nouveau_drm *drm = pci_get_drvdata(pdev);
int ret; int ret;
if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF || if (drm->dev->switch_power_state == DRM_SWITCH_POWER_OFF ||
drm_dev->switch_power_state == DRM_SWITCH_POWER_DYNAMIC_OFF) drm->dev->switch_power_state == DRM_SWITCH_POWER_DYNAMIC_OFF)
return 0; return 0;
ret = nouveau_do_suspend(drm_dev, false); ret = nouveau_do_suspend(drm, false);
if (ret) if (ret)
return ret; return ret;
...@@ -1042,11 +1039,11 @@ int ...@@ -1042,11 +1039,11 @@ int
nouveau_pmops_resume(struct device *dev) nouveau_pmops_resume(struct device *dev)
{ {
struct pci_dev *pdev = to_pci_dev(dev); struct pci_dev *pdev = to_pci_dev(dev);
struct drm_device *drm_dev = pci_get_drvdata(pdev); struct nouveau_drm *drm = pci_get_drvdata(pdev);
int ret; int ret;
if (drm_dev->switch_power_state == DRM_SWITCH_POWER_OFF || if (drm->dev->switch_power_state == DRM_SWITCH_POWER_OFF ||
drm_dev->switch_power_state == DRM_SWITCH_POWER_DYNAMIC_OFF) drm->dev->switch_power_state == DRM_SWITCH_POWER_DYNAMIC_OFF)
return 0; return 0;
pci_set_power_state(pdev, PCI_D0); pci_set_power_state(pdev, PCI_D0);
...@@ -1056,10 +1053,10 @@ nouveau_pmops_resume(struct device *dev) ...@@ -1056,10 +1053,10 @@ nouveau_pmops_resume(struct device *dev)
return ret; return ret;
pci_set_master(pdev); pci_set_master(pdev);
ret = nouveau_do_resume(drm_dev, false); ret = nouveau_do_resume(drm, false);
/* Monitors may have been connected / disconnected during suspend */ /* Monitors may have been connected / disconnected during suspend */
nouveau_display_hpd_resume(drm_dev); nouveau_display_hpd_resume(drm);
return ret; return ret;
} }
...@@ -1067,17 +1064,17 @@ nouveau_pmops_resume(struct device *dev) ...@@ -1067,17 +1064,17 @@ nouveau_pmops_resume(struct device *dev)
static int static int
nouveau_pmops_freeze(struct device *dev) nouveau_pmops_freeze(struct device *dev)
{ {
struct pci_dev *pdev = to_pci_dev(dev); struct nouveau_drm *drm = dev_get_drvdata(dev);
struct drm_device *drm_dev = pci_get_drvdata(pdev);
return nouveau_do_suspend(drm_dev, false); return nouveau_do_suspend(drm, false);
} }
static int static int
nouveau_pmops_thaw(struct device *dev) nouveau_pmops_thaw(struct device *dev)
{ {
struct pci_dev *pdev = to_pci_dev(dev); struct nouveau_drm *drm = dev_get_drvdata(dev);
struct drm_device *drm_dev = pci_get_drvdata(pdev);
return nouveau_do_resume(drm_dev, false); return nouveau_do_resume(drm, false);
} }
bool bool
...@@ -1092,7 +1089,7 @@ static int ...@@ -1092,7 +1089,7 @@ static int
nouveau_pmops_runtime_suspend(struct device *dev) nouveau_pmops_runtime_suspend(struct device *dev)
{ {
struct pci_dev *pdev = to_pci_dev(dev); struct pci_dev *pdev = to_pci_dev(dev);
struct drm_device *drm_dev = pci_get_drvdata(pdev); struct nouveau_drm *drm = pci_get_drvdata(pdev);
int ret; int ret;
if (!nouveau_pmops_runtime()) { if (!nouveau_pmops_runtime()) {
...@@ -1101,12 +1098,12 @@ nouveau_pmops_runtime_suspend(struct device *dev) ...@@ -1101,12 +1098,12 @@ nouveau_pmops_runtime_suspend(struct device *dev)
} }
nouveau_switcheroo_optimus_dsm(); nouveau_switcheroo_optimus_dsm();
ret = nouveau_do_suspend(drm_dev, true); ret = nouveau_do_suspend(drm, true);
pci_save_state(pdev); pci_save_state(pdev);
pci_disable_device(pdev); pci_disable_device(pdev);
pci_ignore_hotplug(pdev); pci_ignore_hotplug(pdev);
pci_set_power_state(pdev, PCI_D3cold); pci_set_power_state(pdev, PCI_D3cold);
drm_dev->switch_power_state = DRM_SWITCH_POWER_DYNAMIC_OFF; drm->dev->switch_power_state = DRM_SWITCH_POWER_DYNAMIC_OFF;
return ret; return ret;
} }
...@@ -1114,9 +1111,8 @@ static int ...@@ -1114,9 +1111,8 @@ static int
nouveau_pmops_runtime_resume(struct device *dev) nouveau_pmops_runtime_resume(struct device *dev)
{ {
struct pci_dev *pdev = to_pci_dev(dev); struct pci_dev *pdev = to_pci_dev(dev);
struct drm_device *drm_dev = pci_get_drvdata(pdev); struct nouveau_drm *drm = pci_get_drvdata(pdev);
struct nouveau_drm *drm = nouveau_drm(drm_dev); struct nvif_device *device = &drm->client.device;
struct nvif_device *device = &nouveau_drm(drm_dev)->client.device;
int ret; int ret;
if (!nouveau_pmops_runtime()) { if (!nouveau_pmops_runtime()) {
...@@ -1131,7 +1127,7 @@ nouveau_pmops_runtime_resume(struct device *dev) ...@@ -1131,7 +1127,7 @@ nouveau_pmops_runtime_resume(struct device *dev)
return ret; return ret;
pci_set_master(pdev); pci_set_master(pdev);
ret = nouveau_do_resume(drm_dev, true); ret = nouveau_do_resume(drm, true);
if (ret) { if (ret) {
NV_ERROR(drm, "resume failed with: %d\n", ret); NV_ERROR(drm, "resume failed with: %d\n", ret);
return ret; return ret;
...@@ -1139,10 +1135,10 @@ nouveau_pmops_runtime_resume(struct device *dev) ...@@ -1139,10 +1135,10 @@ nouveau_pmops_runtime_resume(struct device *dev)
/* do magic */ /* do magic */
nvif_mask(&device->object, 0x088488, (1 << 25), (1 << 25)); nvif_mask(&device->object, 0x088488, (1 << 25), (1 << 25));
drm_dev->switch_power_state = DRM_SWITCH_POWER_ON; drm->dev->switch_power_state = DRM_SWITCH_POWER_ON;
/* Monitors may have been connected / disconnected during suspend */ /* Monitors may have been connected / disconnected during suspend */
nouveau_display_hpd_resume(drm_dev); nouveau_display_hpd_resume(drm);
return ret; return ret;
} }
......
...@@ -325,7 +325,7 @@ bool nouveau_pmops_runtime(void); ...@@ -325,7 +325,7 @@ bool nouveau_pmops_runtime(void);
struct drm_device * struct drm_device *
nouveau_platform_device_create(const struct nvkm_device_tegra_func *, nouveau_platform_device_create(const struct nvkm_device_tegra_func *,
struct platform_device *, struct nvkm_device **); struct platform_device *, struct nvkm_device **);
void nouveau_drm_device_remove(struct drm_device *dev); void nouveau_drm_device_remove(struct nouveau_drm *);
#define NV_PRINTK(l,c,f,a...) do { \ #define NV_PRINTK(l,c,f,a...) do { \
struct nouveau_cli *_cli = (c); \ struct nouveau_cli *_cli = (c); \
......
...@@ -39,8 +39,9 @@ static int nouveau_platform_probe(struct platform_device *pdev) ...@@ -39,8 +39,9 @@ static int nouveau_platform_probe(struct platform_device *pdev)
static void nouveau_platform_remove(struct platform_device *pdev) static void nouveau_platform_remove(struct platform_device *pdev)
{ {
struct drm_device *dev = platform_get_drvdata(pdev); struct nouveau_drm *drm = platform_get_drvdata(pdev);
nouveau_drm_device_remove(dev);
nouveau_drm_device_remove(drm);
} }
#if IS_ENABLED(CONFIG_OF) #if IS_ENABLED(CONFIG_OF)
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
static unsigned int static unsigned int
nouveau_vga_set_decode(struct pci_dev *pdev, bool state) nouveau_vga_set_decode(struct pci_dev *pdev, bool state)
{ {
struct nouveau_drm *drm = nouveau_drm(pci_get_drvdata(pdev)); struct nouveau_drm *drm = pci_get_drvdata(pdev);
struct nvif_object *device = &drm->client.device.object; struct nvif_object *device = &drm->client.device.object;
if (drm->client.device.info.family == NV_DEVICE_INFO_V0_CURIE && if (drm->client.device.info.family == NV_DEVICE_INFO_V0_CURIE &&
...@@ -34,7 +34,8 @@ static void ...@@ -34,7 +34,8 @@ static void
nouveau_switcheroo_set_state(struct pci_dev *pdev, nouveau_switcheroo_set_state(struct pci_dev *pdev,
enum vga_switcheroo_state state) enum vga_switcheroo_state state)
{ {
struct drm_device *dev = pci_get_drvdata(pdev); struct nouveau_drm *drm = pci_get_drvdata(pdev);
struct drm_device *dev = drm->dev;
if ((nouveau_is_optimus() || nouveau_is_v1_dsm()) && state == VGA_SWITCHEROO_OFF) if ((nouveau_is_optimus() || nouveau_is_v1_dsm()) && state == VGA_SWITCHEROO_OFF)
return; return;
...@@ -56,21 +57,22 @@ nouveau_switcheroo_set_state(struct pci_dev *pdev, ...@@ -56,21 +57,22 @@ nouveau_switcheroo_set_state(struct pci_dev *pdev,
static void static void
nouveau_switcheroo_reprobe(struct pci_dev *pdev) nouveau_switcheroo_reprobe(struct pci_dev *pdev)
{ {
struct drm_device *dev = pci_get_drvdata(pdev); struct nouveau_drm *drm = pci_get_drvdata(pdev);
drm_fb_helper_output_poll_changed(dev);
drm_fb_helper_output_poll_changed(drm->dev);
} }
static bool static bool
nouveau_switcheroo_can_switch(struct pci_dev *pdev) nouveau_switcheroo_can_switch(struct pci_dev *pdev)
{ {
struct drm_device *dev = pci_get_drvdata(pdev); struct nouveau_drm *drm = pci_get_drvdata(pdev);
/* /*
* FIXME: open_count is protected by drm_global_mutex but that would lead to * FIXME: open_count is protected by drm_global_mutex but that would lead to
* locking inversion with the driver load path. And the access here is * locking inversion with the driver load path. And the access here is
* completely racy anyway. So don't bother with locking for now. * completely racy anyway. So don't bother with locking for now.
*/ */
return atomic_read(&dev->open_count) == 0; return atomic_read(&drm->dev->open_count) == 0;
} }
static const struct vga_switcheroo_client_ops static const struct vga_switcheroo_client_ops
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment