Re: [PATCH 09/15] drm/nouveau: Remove references to struct drm_device.pdev
Hi Sam Am 24.11.20 um 22:42 schrieb Sam Ravnborg: Hi Thomas. On Tue, Nov 24, 2020 at 12:38:18PM +0100, Thomas Zimmermann wrote: Using struct drm_device.pdev is deprecated. Convert nouveau to struct drm_device.dev. No functional changes. Signed-off-by: Thomas Zimmermann Cc: Ben Skeggs Suggestion to an alternative implmentation below. --- drivers/gpu/drm/nouveau/dispnv04/arb.c | 12 +++- drivers/gpu/drm/nouveau/dispnv04/disp.h | 14 -- drivers/gpu/drm/nouveau/dispnv04/hw.c | 10 ++ drivers/gpu/drm/nouveau/nouveau_abi16.c | 7 --- drivers/gpu/drm/nouveau/nouveau_acpi.c | 2 +- drivers/gpu/drm/nouveau/nouveau_bios.c | 11 --- drivers/gpu/drm/nouveau/nouveau_connector.c | 10 ++ drivers/gpu/drm/nouveau/nouveau_drm.c | 5 ++--- drivers/gpu/drm/nouveau/nouveau_fbcon.c | 6 -- drivers/gpu/drm/nouveau/nouveau_vga.c | 20 10 files changed, 58 insertions(+), 39 deletions(-) diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c index d204ea8a5618..7cc683b8dc7a 100644 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c @@ -110,6 +110,9 @@ static int call_lvds_manufacturer_script(struct drm_device *dev, struct dcb_outp struct nvbios *bios = >vbios; uint8_t sub = bios->data[bios->fp.xlated_entry + script] + (bios->fp.link_c_increment && dcbent->or & DCB_OUTPUT_C ? 1 : 0); uint16_t scriptofs = ROM16(bios->data[bios->init_script_tbls_ptr + sub * 2]); +#ifdef __powerpc__ + struct pci_dev *pdev = to_pci_dev(dev->dev); +#endif Or int device = 0; if (!bios->fp.xlated_entry || !sub || !scriptofs) return -EINVAL; @@ -123,8 +126,8 @@ static int call_lvds_manufacturer_script(struct drm_device *dev, struct dcb_outp #ifdef __powerpc__ /* Powerbook specific quirks */ device = to_pci_dev(dev->dev)->device; if (script == LVDS_RESET && (device == 0x0179 || device == 0x0189 || device == 0x0329)) I see the point, but I'm trying to not change the existing implementation too much. if (script == LVDS_RESET && - (dev->pdev->device == 0x0179 || dev->pdev->device == 0x0189 || -dev->pdev->device == 0x0329)) + (pdev->device == 0x0179 || pdev->device == 0x0189 || +pdev->device == 0x0329)) nv_write_tmds(dev, dcbent->or, 0, 0x02, 0x72); #endif diff --git a/drivers/gpu/drm/nouveau/nouveau_fbcon.c b/drivers/gpu/drm/nouveau/nouveau_fbcon.c index 24ec5339efb4..4fc0fa696461 100644 --- a/drivers/gpu/drm/nouveau/nouveau_fbcon.c +++ b/drivers/gpu/drm/nouveau/nouveau_fbcon.c @@ -396,7 +396,9 @@ nouveau_fbcon_create(struct drm_fb_helper *helper, NV_INFO(drm, "allocated %dx%d fb: 0x%llx, bo %p\n", fb->width, fb->height, nvbo->offset, nvbo); - vga_switcheroo_client_fb_set(dev->pdev, info); + if (dev_is_pci(dev->dev)) + vga_switcheroo_client_fb_set(to_pci_dev(dev->dev), info); + I cannot see why dev_is_pci() is needed here. So I am obviously missing something :-( vga_switcheroo_client_fb_set() expects a PCI device. It's a bit of a stretch, but at least it is possible to pass NULL for non-PCI devices. Passing the upcasted dev->dev is just garbage. As the VGA switcheroo is only relevant for PCI devices, I added the branching to make this work reliably. Best regards Thomas return 0; out_unlock: @@ -548,7 +550,7 @@ nouveau_fbcon_init(struct drm_device *dev) int ret; if (!dev->mode_config.num_crtc || - (dev->pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA) + (to_pci_dev(dev->dev)->class >> 8) != PCI_CLASS_DISPLAY_VGA) return 0; fbcon = kzalloc(sizeof(struct nouveau_fbdev), GFP_KERNEL); diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c index c85dd8afa3c3..7c4b374b3eca 100644 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c @@ -87,18 +87,20 @@ nouveau_vga_init(struct nouveau_drm *drm) { struct drm_device *dev = drm->dev; bool runtime = nouveau_pmops_runtime(); + struct pci_dev *pdev; /* only relevant for PCI devices */ - if (!dev->pdev) + if (!dev_is_pci(dev->dev)) return; + pdev = to_pci_dev(dev->dev); - vga_client_register(dev->pdev, dev, NULL, nouveau_vga_set_decode); + vga_client_register(pdev, dev, NULL, nouveau_vga_set_decode); /* don't register Thunderbolt eGPU with vga_switcheroo */ - if (pci_is_thunderbolt_attached(dev->pdev)) + if (pci_is_thunderbolt_attached(pdev)) return; - vga_switcheroo_register_client(dev->pdev, _switcheroo_ops, runtime); + vga_switcheroo_register_client(pdev, _switcheroo_ops, runtime); if (runtime &&
Re: [PATCH 09/15] drm/nouveau: Remove references to struct drm_device.pdev
Hi Thomas. On Tue, Nov 24, 2020 at 12:38:18PM +0100, Thomas Zimmermann wrote: > Using struct drm_device.pdev is deprecated. Convert nouveau to struct > drm_device.dev. No functional changes. > > Signed-off-by: Thomas Zimmermann > Cc: Ben Skeggs Suggestion to an alternative implmentation below. > --- > drivers/gpu/drm/nouveau/dispnv04/arb.c | 12 +++- > drivers/gpu/drm/nouveau/dispnv04/disp.h | 14 -- > drivers/gpu/drm/nouveau/dispnv04/hw.c | 10 ++ > drivers/gpu/drm/nouveau/nouveau_abi16.c | 7 --- > drivers/gpu/drm/nouveau/nouveau_acpi.c | 2 +- > drivers/gpu/drm/nouveau/nouveau_bios.c | 11 --- > drivers/gpu/drm/nouveau/nouveau_connector.c | 10 ++ > drivers/gpu/drm/nouveau/nouveau_drm.c | 5 ++--- > drivers/gpu/drm/nouveau/nouveau_fbcon.c | 6 -- > drivers/gpu/drm/nouveau/nouveau_vga.c | 20 > 10 files changed, 58 insertions(+), 39 deletions(-) > > diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c > b/drivers/gpu/drm/nouveau/nouveau_bios.c > index d204ea8a5618..7cc683b8dc7a 100644 > --- a/drivers/gpu/drm/nouveau/nouveau_bios.c > +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c > @@ -110,6 +110,9 @@ static int call_lvds_manufacturer_script(struct > drm_device *dev, struct dcb_outp > struct nvbios *bios = >vbios; > uint8_t sub = bios->data[bios->fp.xlated_entry + script] + > (bios->fp.link_c_increment && dcbent->or & DCB_OUTPUT_C ? 1 : 0); > uint16_t scriptofs = ROM16(bios->data[bios->init_script_tbls_ptr + sub > * 2]); > +#ifdef __powerpc__ > + struct pci_dev *pdev = to_pci_dev(dev->dev); > +#endif Or int device = 0; > > if (!bios->fp.xlated_entry || !sub || !scriptofs) > return -EINVAL; > @@ -123,8 +126,8 @@ static int call_lvds_manufacturer_script(struct > drm_device *dev, struct dcb_outp > #ifdef __powerpc__ > /* Powerbook specific quirks */ device = to_pci_dev(dev->dev)->device; if (script == LVDS_RESET && (device == 0x0179 || device == 0x0189 || device == 0x0329)) > if (script == LVDS_RESET && > - (dev->pdev->device == 0x0179 || dev->pdev->device == 0x0189 || > - dev->pdev->device == 0x0329)) > + (pdev->device == 0x0179 || pdev->device == 0x0189 || > + pdev->device == 0x0329)) > nv_write_tmds(dev, dcbent->or, 0, 0x02, 0x72); > #endif > > diff --git a/drivers/gpu/drm/nouveau/nouveau_fbcon.c > b/drivers/gpu/drm/nouveau/nouveau_fbcon.c > index 24ec5339efb4..4fc0fa696461 100644 > --- a/drivers/gpu/drm/nouveau/nouveau_fbcon.c > +++ b/drivers/gpu/drm/nouveau/nouveau_fbcon.c > @@ -396,7 +396,9 @@ nouveau_fbcon_create(struct drm_fb_helper *helper, > NV_INFO(drm, "allocated %dx%d fb: 0x%llx, bo %p\n", > fb->width, fb->height, nvbo->offset, nvbo); > > - vga_switcheroo_client_fb_set(dev->pdev, info); > + if (dev_is_pci(dev->dev)) > + vga_switcheroo_client_fb_set(to_pci_dev(dev->dev), info); > + I cannot see why dev_is_pci() is needed here. So I am obviously missing something :-( > return 0; > > out_unlock: > @@ -548,7 +550,7 @@ nouveau_fbcon_init(struct drm_device *dev) > int ret; > > if (!dev->mode_config.num_crtc || > - (dev->pdev->class >> 8) != PCI_CLASS_DISPLAY_VGA) > + (to_pci_dev(dev->dev)->class >> 8) != PCI_CLASS_DISPLAY_VGA) > return 0; > > fbcon = kzalloc(sizeof(struct nouveau_fbdev), GFP_KERNEL); > diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c > b/drivers/gpu/drm/nouveau/nouveau_vga.c > index c85dd8afa3c3..7c4b374b3eca 100644 > --- a/drivers/gpu/drm/nouveau/nouveau_vga.c > +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c > @@ -87,18 +87,20 @@ nouveau_vga_init(struct nouveau_drm *drm) > { > struct drm_device *dev = drm->dev; > bool runtime = nouveau_pmops_runtime(); > + struct pci_dev *pdev; > > /* only relevant for PCI devices */ > - if (!dev->pdev) > + if (!dev_is_pci(dev->dev)) > return; > + pdev = to_pci_dev(dev->dev); > > - vga_client_register(dev->pdev, dev, NULL, nouveau_vga_set_decode); > + vga_client_register(pdev, dev, NULL, nouveau_vga_set_decode); > > /* don't register Thunderbolt eGPU with vga_switcheroo */ > - if (pci_is_thunderbolt_attached(dev->pdev)) > + if (pci_is_thunderbolt_attached(pdev)) > return; > > - vga_switcheroo_register_client(dev->pdev, _switcheroo_ops, > runtime); > + vga_switcheroo_register_client(pdev, _switcheroo_ops, runtime); > > if (runtime && nouveau_is_v1_dsm() && !nouveau_is_optimus()) > vga_switcheroo_init_domain_pm_ops(drm->dev->dev, > >vga_pm_domain); > @@ -109,17 +111,19 @@ nouveau_vga_fini(struct nouveau_drm *drm) > { > struct drm_device *dev = drm->dev; > bool runtime = nouveau_pmops_runtime(); > + struct pci_dev *pdev; > > /* only
[PATCH 09/15] drm/nouveau: Remove references to struct drm_device.pdev
Using struct drm_device.pdev is deprecated. Convert nouveau to struct drm_device.dev. No functional changes. Signed-off-by: Thomas Zimmermann Cc: Ben Skeggs --- drivers/gpu/drm/nouveau/dispnv04/arb.c | 12 +++- drivers/gpu/drm/nouveau/dispnv04/disp.h | 14 -- drivers/gpu/drm/nouveau/dispnv04/hw.c | 10 ++ drivers/gpu/drm/nouveau/nouveau_abi16.c | 7 --- drivers/gpu/drm/nouveau/nouveau_acpi.c | 2 +- drivers/gpu/drm/nouveau/nouveau_bios.c | 11 --- drivers/gpu/drm/nouveau/nouveau_connector.c | 10 ++ drivers/gpu/drm/nouveau/nouveau_drm.c | 5 ++--- drivers/gpu/drm/nouveau/nouveau_fbcon.c | 6 -- drivers/gpu/drm/nouveau/nouveau_vga.c | 20 10 files changed, 58 insertions(+), 39 deletions(-) diff --git a/drivers/gpu/drm/nouveau/dispnv04/arb.c b/drivers/gpu/drm/nouveau/dispnv04/arb.c index 9d4a2d97507e..1d3542d6006b 100644 --- a/drivers/gpu/drm/nouveau/dispnv04/arb.c +++ b/drivers/gpu/drm/nouveau/dispnv04/arb.c @@ -200,16 +200,17 @@ nv04_update_arb(struct drm_device *dev, int VClk, int bpp, int MClk = nouveau_hw_get_clock(dev, PLL_MEMORY); int NVClk = nouveau_hw_get_clock(dev, PLL_CORE); uint32_t cfg1 = nvif_rd32(device, NV04_PFB_CFG1); + struct pci_dev *pdev = to_pci_dev(dev->dev); sim_data.pclk_khz = VClk; sim_data.mclk_khz = MClk; sim_data.nvclk_khz = NVClk; sim_data.bpp = bpp; sim_data.two_heads = nv_two_heads(dev); - if ((dev->pdev->device & 0x) == 0x01a0 /*CHIPSET_NFORCE*/ || - (dev->pdev->device & 0x) == 0x01f0 /*CHIPSET_NFORCE2*/) { + if ((pdev->device & 0x) == 0x01a0 /*CHIPSET_NFORCE*/ || + (pdev->device & 0x) == 0x01f0 /*CHIPSET_NFORCE2*/) { uint32_t type; - int domain = pci_domain_nr(dev->pdev->bus); + int domain = pci_domain_nr(pdev->bus); pci_read_config_dword(pci_get_domain_bus_and_slot(domain, 0, 1), 0x7c, ); @@ -251,11 +252,12 @@ void nouveau_calc_arb(struct drm_device *dev, int vclk, int bpp, int *burst, int *lwm) { struct nouveau_drm *drm = nouveau_drm(dev); + struct pci_dev *pdev = to_pci_dev(dev->dev); if (drm->client.device.info.family < NV_DEVICE_INFO_V0_KELVIN) nv04_update_arb(dev, vclk, bpp, burst, lwm); - else if ((dev->pdev->device & 0xfff0) == 0x0240 /*CHIPSET_C51*/ || -(dev->pdev->device & 0xfff0) == 0x03d0 /*CHIPSET_C512*/) { + else if ((pdev->device & 0xfff0) == 0x0240 /*CHIPSET_C51*/ || +(pdev->device & 0xfff0) == 0x03d0 /*CHIPSET_C512*/) { *burst = 128; *lwm = 0x0480; } else diff --git a/drivers/gpu/drm/nouveau/dispnv04/disp.h b/drivers/gpu/drm/nouveau/dispnv04/disp.h index 5ace5e906949..f0a24126641a 100644 --- a/drivers/gpu/drm/nouveau/dispnv04/disp.h +++ b/drivers/gpu/drm/nouveau/dispnv04/disp.h @@ -130,7 +130,7 @@ static inline bool nv_two_heads(struct drm_device *dev) { struct nouveau_drm *drm = nouveau_drm(dev); - const int impl = dev->pdev->device & 0x0ff0; + const int impl = to_pci_dev(dev->dev)->device & 0x0ff0; if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_CELSIUS && impl != 0x0100 && impl != 0x0150 && impl != 0x01a0 && impl != 0x0200) @@ -142,14 +142,14 @@ nv_two_heads(struct drm_device *dev) static inline bool nv_gf4_disp_arch(struct drm_device *dev) { - return nv_two_heads(dev) && (dev->pdev->device & 0x0ff0) != 0x0110; + return nv_two_heads(dev) && (to_pci_dev(dev->dev)->device & 0x0ff0) != 0x0110; } static inline bool nv_two_reg_pll(struct drm_device *dev) { struct nouveau_drm *drm = nouveau_drm(dev); - const int impl = dev->pdev->device & 0x0ff0; + const int impl = to_pci_dev(dev->dev)->device & 0x0ff0; if (impl == 0x0310 || impl == 0x0340 || drm->client.device.info.family >= NV_DEVICE_INFO_V0_CURIE) return true; @@ -160,9 +160,11 @@ static inline bool nv_match_device(struct drm_device *dev, unsigned device, unsigned sub_vendor, unsigned sub_device) { - return dev->pdev->device == device && - dev->pdev->subsystem_vendor == sub_vendor && - dev->pdev->subsystem_device == sub_device; + struct pci_dev *pdev = to_pci_dev(dev->dev); + + return pdev->device == device && + pdev->subsystem_vendor == sub_vendor && + pdev->subsystem_device == sub_device; } #include diff --git a/drivers/gpu/drm/nouveau/dispnv04/hw.c b/drivers/gpu/drm/nouveau/dispnv04/hw.c index b674d68ef28a..f7d35657aa64 100644 --- a/drivers/gpu/drm/nouveau/dispnv04/hw.c +++ b/drivers/gpu/drm/nouveau/dispnv04/hw.c @@ -214,14 +214,15 @@ nouveau_hw_pllvals_to_clk(struct nvkm_pll_vals *pv) int nouveau_hw_get_clock(struct