Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/gma500: Move GTT memory-range setup into helper

Move the setup code for GTT/GATT memory ranges into a new helper and
call the function from psb_gtt_init() and psb_gtt_resume(). Removes
code duplication.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Acked-by: Patrik Jakobsson <patrik.r.jakobsson@gmail.com>
Signed-off-by: Patrik Jakobsson <patrik.r.jakobsson@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220308195222.13471-13-tzimmermann@suse.de

authored by

Thomas Zimmermann and committed by
Patrik Jakobsson
07739597 5169f359

+76 -101
+76 -101
drivers/gpu/drm/gma500/gtt.c
··· 182 182 (void)ioread32(pdev->gtt_map + i - 1); 183 183 } 184 184 185 + static void psb_gtt_init_ranges(struct drm_psb_private *dev_priv) 186 + { 187 + struct drm_device *dev = &dev_priv->dev; 188 + struct pci_dev *pdev = to_pci_dev(dev->dev); 189 + struct psb_gtt *pg = &dev_priv->gtt; 190 + resource_size_t gtt_phys_start, mmu_gatt_start, gtt_start, gtt_pages, 191 + gatt_start, gatt_pages; 192 + struct resource *gtt_mem; 193 + 194 + /* The root resource we allocate address space from */ 195 + gtt_phys_start = dev_priv->pge_ctl & PAGE_MASK; 196 + 197 + /* 198 + * The video MMU has a HW bug when accessing 0x0d0000000. Make 199 + * GATT start at 0x0e0000000. This doesn't actually matter for 200 + * us now, but maybe will if the video acceleration ever gets 201 + * opened up. 202 + */ 203 + mmu_gatt_start = 0xe0000000; 204 + 205 + gtt_start = pci_resource_start(pdev, PSB_GTT_RESOURCE); 206 + gtt_pages = pci_resource_len(pdev, PSB_GTT_RESOURCE) >> PAGE_SHIFT; 207 + 208 + /* CDV doesn't report this. In which case the system has 64 gtt pages */ 209 + if (!gtt_start || !gtt_pages) { 210 + dev_dbg(dev->dev, "GTT PCI BAR not initialized.\n"); 211 + gtt_pages = 64; 212 + gtt_start = dev_priv->pge_ctl; 213 + } 214 + 215 + gatt_start = pci_resource_start(pdev, PSB_GATT_RESOURCE); 216 + gatt_pages = pci_resource_len(pdev, PSB_GATT_RESOURCE) >> PAGE_SHIFT; 217 + 218 + if (!gatt_pages || !gatt_start) { 219 + static struct resource fudge; /* Preferably peppermint */ 220 + 221 + /* 222 + * This can occur on CDV systems. Fudge it in this case. We 223 + * really don't care what imaginary space is being allocated 224 + * at this point. 225 + */ 226 + dev_dbg(dev->dev, "GATT PCI BAR not initialized.\n"); 227 + gatt_start = 0x40000000; 228 + gatt_pages = (128 * 1024 * 1024) >> PAGE_SHIFT; 229 + 230 + /* 231 + * This is a little confusing but in fact the GTT is providing 232 + * a view from the GPU into memory and not vice versa. As such 233 + * this is really allocating space that is not the same as the 234 + * CPU address space on CDV. 235 + */ 236 + fudge.start = 0x40000000; 237 + fudge.end = 0x40000000 + 128 * 1024 * 1024 - 1; 238 + fudge.name = "fudge"; 239 + fudge.flags = IORESOURCE_MEM; 240 + 241 + gtt_mem = &fudge; 242 + } else { 243 + gtt_mem = &pdev->resource[PSB_GATT_RESOURCE]; 244 + } 245 + 246 + pg->gtt_phys_start = gtt_phys_start; 247 + pg->mmu_gatt_start = mmu_gatt_start; 248 + pg->gtt_start = gtt_start; 249 + pg->gtt_pages = gtt_pages; 250 + pg->gatt_start = gatt_start; 251 + pg->gatt_pages = gatt_pages; 252 + dev_priv->gtt_mem = gtt_mem; 253 + } 254 + 185 255 int psb_gtt_init(struct drm_device *dev) 186 256 { 187 257 struct drm_psb_private *dev_priv = to_drm_psb_private(dev); 188 - struct pci_dev *pdev = to_pci_dev(dev->dev); 189 258 struct psb_gtt *pg = &dev_priv->gtt; 190 - unsigned gtt_pages; 191 259 int ret; 192 260 193 261 mutex_init(&dev_priv->gtt_mutex); ··· 264 196 if (ret) 265 197 goto err_mutex_destroy; 266 198 267 - /* The root resource we allocate address space from */ 268 - pg->gtt_phys_start = dev_priv->pge_ctl & PAGE_MASK; 199 + psb_gtt_init_ranges(dev_priv); 269 200 270 - /* 271 - * The video mmu has a hw bug when accessing 0x0D0000000. 272 - * Make gatt start at 0x0e000,0000. This doesn't actually 273 - * matter for us but may do if the video acceleration ever 274 - * gets opened up. 275 - */ 276 - pg->mmu_gatt_start = 0xE0000000; 277 - 278 - pg->gtt_start = pci_resource_start(pdev, PSB_GTT_RESOURCE); 279 - gtt_pages = pci_resource_len(pdev, PSB_GTT_RESOURCE) 280 - >> PAGE_SHIFT; 281 - /* CDV doesn't report this. In which case the system has 64 gtt pages */ 282 - if (pg->gtt_start == 0 || gtt_pages == 0) { 283 - dev_dbg(dev->dev, "GTT PCI BAR not initialized.\n"); 284 - gtt_pages = 64; 285 - pg->gtt_start = dev_priv->pge_ctl; 286 - } 287 - 288 - pg->gatt_start = pci_resource_start(pdev, PSB_GATT_RESOURCE); 289 - pg->gatt_pages = pci_resource_len(pdev, PSB_GATT_RESOURCE) 290 - >> PAGE_SHIFT; 291 - dev_priv->gtt_mem = &pdev->resource[PSB_GATT_RESOURCE]; 292 - 293 - if (pg->gatt_pages == 0 || pg->gatt_start == 0) { 294 - static struct resource fudge; /* Preferably peppermint */ 295 - /* This can occur on CDV systems. Fudge it in this case. 296 - We really don't care what imaginary space is being allocated 297 - at this point */ 298 - dev_dbg(dev->dev, "GATT PCI BAR not initialized.\n"); 299 - pg->gatt_start = 0x40000000; 300 - pg->gatt_pages = (128 * 1024 * 1024) >> PAGE_SHIFT; 301 - /* This is a little confusing but in fact the GTT is providing 302 - a view from the GPU into memory and not vice versa. As such 303 - this is really allocating space that is not the same as the 304 - CPU address space on CDV */ 305 - fudge.start = 0x40000000; 306 - fudge.end = 0x40000000 + 128 * 1024 * 1024 - 1; 307 - fudge.name = "fudge"; 308 - fudge.flags = IORESOURCE_MEM; 309 - dev_priv->gtt_mem = &fudge; 310 - } 311 - 312 - pg->gtt_pages = gtt_pages; 313 - 314 - dev_priv->gtt_map = ioremap(pg->gtt_phys_start, gtt_pages << PAGE_SHIFT); 201 + dev_priv->gtt_map = ioremap(pg->gtt_phys_start, pg->gtt_pages << PAGE_SHIFT); 315 202 if (!dev_priv->gtt_map) { 316 203 dev_err(dev->dev, "Failure to map gtt.\n"); 317 204 ret = -ENOMEM; ··· 287 264 int psb_gtt_resume(struct drm_device *dev) 288 265 { 289 266 struct drm_psb_private *dev_priv = to_drm_psb_private(dev); 290 - struct pci_dev *pdev = to_pci_dev(dev->dev); 291 267 struct psb_gtt *pg = &dev_priv->gtt; 292 - unsigned int gtt_pages; 268 + unsigned int old_gtt_pages = pg->gtt_pages; 293 269 int ret; 294 270 295 271 /* Enable the GTT */ ··· 296 274 if (ret) 297 275 return ret; 298 276 299 - /* The root resource we allocate address space from */ 300 - pg->gtt_phys_start = dev_priv->pge_ctl & PAGE_MASK; 277 + psb_gtt_init_ranges(dev_priv); 301 278 302 - /* 303 - * The video mmu has a hw bug when accessing 0x0D0000000. 304 - * Make gatt start at 0x0e000,0000. This doesn't actually 305 - * matter for us but may do if the video acceleration ever 306 - * gets opened up. 307 - */ 308 - pg->mmu_gatt_start = 0xE0000000; 309 - 310 - pg->gtt_start = pci_resource_start(pdev, PSB_GTT_RESOURCE); 311 - gtt_pages = pci_resource_len(pdev, PSB_GTT_RESOURCE) >> PAGE_SHIFT; 312 - /* CDV doesn't report this. In which case the system has 64 gtt pages */ 313 - if (pg->gtt_start == 0 || gtt_pages == 0) { 314 - dev_dbg(dev->dev, "GTT PCI BAR not initialized.\n"); 315 - gtt_pages = 64; 316 - pg->gtt_start = dev_priv->pge_ctl; 317 - } 318 - 319 - pg->gatt_start = pci_resource_start(pdev, PSB_GATT_RESOURCE); 320 - pg->gatt_pages = pci_resource_len(pdev, PSB_GATT_RESOURCE) >> PAGE_SHIFT; 321 - dev_priv->gtt_mem = &pdev->resource[PSB_GATT_RESOURCE]; 322 - 323 - if (pg->gatt_pages == 0 || pg->gatt_start == 0) { 324 - static struct resource fudge; /* Preferably peppermint */ 325 - /* 326 - * This can occur on CDV systems. Fudge it in this case. We 327 - * really don't care what imaginary space is being allocated 328 - * at this point. 329 - */ 330 - dev_dbg(dev->dev, "GATT PCI BAR not initialized.\n"); 331 - pg->gatt_start = 0x40000000; 332 - pg->gatt_pages = (128 * 1024 * 1024) >> PAGE_SHIFT; 333 - /* 334 - * This is a little confusing but in fact the GTT is providing 335 - * a view from the GPU into memory and not vice versa. As such 336 - * this is really allocating space that is not the same as the 337 - * CPU address space on CDV. 338 - */ 339 - fudge.start = 0x40000000; 340 - fudge.end = 0x40000000 + 128 * 1024 * 1024 - 1; 341 - fudge.name = "fudge"; 342 - fudge.flags = IORESOURCE_MEM; 343 - dev_priv->gtt_mem = &fudge; 344 - } 345 - 346 - if (gtt_pages != pg->gtt_pages) { 279 + if (old_gtt_pages != pg->gtt_pages) { 347 280 dev_err(dev->dev, "GTT resume error.\n"); 348 - ret = -EINVAL; 281 + ret = -ENODEV; 349 282 goto err_psb_gtt_disable; 350 283 } 351 - 352 - pg->gtt_pages = gtt_pages; 353 284 354 285 psb_gtt_clear(dev_priv); 355 286