Skip to content

Commit

Permalink
Reapply "drm/nouveau/firmware: Fix SG_DEBUG error with nvkm_firmware_…
Browse files Browse the repository at this point in the history
…ctor()"

This commit fixes a kernel BUG (which ends up resulting in a hang) on a Lenovo
ThinkBook 14 G4+ ARA with AMD + NVIDIA graphics.

This reverts commit a222a64.

Signed-off-by: Mingcong Bai <baimingcong@uniontech.com>
Signed-off-by: WangYuli <wangyuli@uniontech.com>
  • Loading branch information
Avenger-285714 committed Jul 11, 2024
1 parent 2c3e81c commit 8a14153
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions drivers/gpu/drm/nouveau/nvkm/core/firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ nvkm_firmware_dtor(struct nvkm_firmware *fw)
break;
case NVKM_FIRMWARE_IMG_DMA:
nvkm_memory_unref(&memory);
dma_free_coherent(fw->device->dev, sg_dma_len(&fw->mem.sgl), fw->img, fw->phys);
dma_unmap_single(fw->device->dev, fw->phys, sg_dma_len(&fw->mem.sgl),
DMA_TO_DEVICE);
kfree(fw->img);
break;
case NVKM_FIRMWARE_IMG_SGT:
nvkm_memory_unref(&memory);
Expand Down Expand Up @@ -235,14 +237,17 @@ nvkm_firmware_ctor(const struct nvkm_firmware_func *func, const char *name,
fw->img = kmemdup(src, fw->len, GFP_KERNEL);
break;
case NVKM_FIRMWARE_IMG_DMA: {
dma_addr_t addr;

len = ALIGN(fw->len, PAGE_SIZE);

fw->img = dma_alloc_coherent(fw->device->dev, len, &addr, GFP_KERNEL);
if (fw->img) {
memcpy(fw->img, src, fw->len);
fw->phys = addr;
fw->img = kmalloc(len, GFP_KERNEL);
if (!fw->img)
return -ENOMEM;

memcpy(fw->img, src, fw->len);
fw->phys = dma_map_single(fw->device->dev, fw->img, len, DMA_TO_DEVICE);
if (dma_mapping_error(fw->device->dev, fw->phys)) {
kfree(fw->img);
return -EFAULT;
}

sg_init_one(&fw->mem.sgl, fw->img, len);
Expand Down

0 comments on commit 8a14153

Please sign in to comment.