Skip to content

Commit 901a408

Browse files
hoshinolinajannau
authored andcommitted
rust: kernel: platform: Add Device.set_dma_masks()
Allows drivers to configure the DMA masks for a device. Implemented here, not in device, because it requires a mutable platform device reference this way (device::Device is a safely clonable reference). Signed-off-by: Asahi Lina <lina@asahilina.net>
1 parent 5f153d2 commit 901a408

3 files changed

Lines changed: 23 additions & 0 deletions

File tree

rust/bindings/bindings_helper.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/blk_types.h>
1717
#include <linux/blkdev.h>
1818
#include <linux/delay.h>
19+
#include <linux/dma-mapping.h>
1920
#include <linux/errname.h>
2021
#include <linux/ethtool.h>
2122
#include <linux/firmware.h>

rust/helpers/device.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
// SPDX-License-Identifier: GPL-2.0
22

33
#include <linux/device.h>
4+
#include <linux/dma-mapping.h>
5+
6+
void *rust_helper_dev_get_drvdata(struct device *dev)
7+
{
8+
return dev_get_drvdata(dev);
9+
}
410

511
int rust_helper_devm_add_action(struct device *dev,
612
void (*action)(void *),
713
void *data)
814
{
915
return devm_add_action(dev, action, data);
1016
}
17+
18+
const char *rust_helper_dev_name(const struct device *dev)
19+
{
20+
return dev_name(dev);
21+
}
22+
23+
int rust_helper_dma_set_mask_and_coherent(struct device *dev, u64 mask)
24+
{
25+
return dma_set_mask_and_coherent(dev, mask);
26+
}

rust/kernel/platform.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,12 @@ impl Device {
216216
unsafe { container_of!(self.dev.as_raw(), bindings::platform_device, dev) }.cast_mut()
217217
}
218218

219+
/// Sets the DMA masks (normal and coherent) for a platform device.
220+
pub fn set_dma_masks(&mut self, mask: u64) -> Result {
221+
// SAFETY: `self.ptr` is valid by the type invariant.
222+
to_result(unsafe { bindings::dma_set_mask_and_coherent(&mut (*self.ptr).dev, mask) })
223+
}
224+
219225
/// Gets a system resources of a platform device.
220226
pub fn get_resource(&mut self, rtype: IoResource, num: usize) -> Result<Resource> {
221227
// SAFETY: `self.ptr` is valid by the type invariant.

0 commit comments

Comments
 (0)