Skip to content

Commit f97ec5d

Browse files
gwendalcrJiri Kosina
authored andcommitted
HID: intel-ish-hid: Use dma_alloc_coherent for firmware update
Allocating memory with kmalloc and GPF_DMA32 is not allowed, the allocator will ignore the attribute. Instead, use dma_alloc_coherent() API as we allocate a small amount of memory to transfer firmware fragment to the ISH. On Arcada chromebook, after the patch the warning: "Unexpected gfp: 0x4 (GFP_DMA32). Fixing up to gfp: 0xcc0 (GFP_KERNEL). Fix your code!" is gone. The ISH firmware is loaded properly and we can interact with the ISH: > ectool --name cros_ish version ... Build info: arcada_ish_v2.0.3661+3c1a1c1ae0 2022-02-08 05:37:47 @localhost Tool version: v2.0.12300-900b03ec7f 2022-02-08 10:01:48 @localhost Fixes: commit 91b2281 ("HID: intel-ish-hid: ISH firmware loader client driver") Signed-off-by: Gwendal Grignou <gwendal@chromium.org> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Cc: stable@vger.kernel.org Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent fe23b6b commit f97ec5d

1 file changed

Lines changed: 3 additions & 26 deletions

File tree

drivers/hid/intel-ish-hid/ishtp-fw-loader.c

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -661,21 +661,12 @@ static int ish_fw_xfer_direct_dma(struct ishtp_cl_data *client_data,
661661
*/
662662
payload_max_size &= ~(L1_CACHE_BYTES - 1);
663663

664-
dma_buf = kmalloc(payload_max_size, GFP_KERNEL | GFP_DMA32);
664+
dma_buf = dma_alloc_coherent(devc, payload_max_size, &dma_buf_phy, GFP_KERNEL);
665665
if (!dma_buf) {
666666
client_data->flag_retry = true;
667667
return -ENOMEM;
668668
}
669669

670-
dma_buf_phy = dma_map_single(devc, dma_buf, payload_max_size,
671-
DMA_TO_DEVICE);
672-
if (dma_mapping_error(devc, dma_buf_phy)) {
673-
dev_err(cl_data_to_dev(client_data), "DMA map failed\n");
674-
client_data->flag_retry = true;
675-
rv = -ENOMEM;
676-
goto end_err_dma_buf_release;
677-
}
678-
679670
ldr_xfer_dma_frag.fragment.hdr.command = LOADER_CMD_XFER_FRAGMENT;
680671
ldr_xfer_dma_frag.fragment.xfer_mode = LOADER_XFER_MODE_DIRECT_DMA;
681672
ldr_xfer_dma_frag.ddr_phys_addr = (u64)dma_buf_phy;
@@ -695,14 +686,7 @@ static int ish_fw_xfer_direct_dma(struct ishtp_cl_data *client_data,
695686
ldr_xfer_dma_frag.fragment.size = fragment_size;
696687
memcpy(dma_buf, &fw->data[fragment_offset], fragment_size);
697688

698-
dma_sync_single_for_device(devc, dma_buf_phy,
699-
payload_max_size,
700-
DMA_TO_DEVICE);
701-
702-
/*
703-
* Flush cache here because the dma_sync_single_for_device()
704-
* does not do for x86.
705-
*/
689+
/* Flush cache to be sure the data is in main memory. */
706690
clflush_cache_range(dma_buf, payload_max_size);
707691

708692
dev_dbg(cl_data_to_dev(client_data),
@@ -725,15 +709,8 @@ static int ish_fw_xfer_direct_dma(struct ishtp_cl_data *client_data,
725709
fragment_offset += fragment_size;
726710
}
727711

728-
dma_unmap_single(devc, dma_buf_phy, payload_max_size, DMA_TO_DEVICE);
729-
kfree(dma_buf);
730-
return 0;
731-
732712
end_err_resp_buf_release:
733-
/* Free ISH buffer if not done already, in error case */
734-
dma_unmap_single(devc, dma_buf_phy, payload_max_size, DMA_TO_DEVICE);
735-
end_err_dma_buf_release:
736-
kfree(dma_buf);
713+
dma_free_coherent(devc, payload_max_size, dma_buf, dma_buf_phy);
737714
return rv;
738715
}
739716

0 commit comments

Comments
 (0)