-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drivers: fuel_gauge: kernel drivers use syscalls
The fuel gauge API doesn't make use of syscalls with device drivers, which is not congruent with Zephyr's security model. Correct the fuel gauge API to only allow access to fuel gauge device drivers functionality via syscalls to keep with Zephyr's security model. Signed-off-by: Aaron Massey <aaronmassey@google.com>
- Loading branch information
1 parent
7d83bf7
commit 6cdef08
Showing
10 changed files
with
198 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
add_subdirectory_ifdef(CONFIG_SBS_GAUGE_NEW_API sbs_gauge) | ||
|
||
zephyr_library_sources_ifdef(CONFIG_USERSPACE fuel_gauge_syscall_handlers.c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/syscall_handler.h> | ||
#include <zephyr/drivers/fuel_gauge.h> | ||
|
||
static inline int z_vrfy_fuel_gauge_get_prop(const struct device *dev, | ||
struct fuel_gauge_get_property *props, | ||
size_t props_len) | ||
{ | ||
struct fuel_gauge_get_property k_props[props_len]; | ||
|
||
Z_OOPS(Z_SYSCALL_DRIVER_FUEL_GAUGE(dev, get_property)); | ||
|
||
Z_OOPS(z_user_from_copy(k_props, props, | ||
props_len * sizeof(struct fuel_gauge_get_property))); | ||
|
||
int ret = z_impl_fuel_gauge_get_prop(dev, k_props, props_len); | ||
|
||
Z_OOPS(z_user_to_copy(props, k_props, props_len * sizeof(struct fuel_gauge_get_property))); | ||
|
||
return ret; | ||
} | ||
|
||
#include <syscalls/fuel_gauge_get_prop_mrsh.c> | ||
|
||
static inline int z_vrfy_fuel_gauge_set_prop(const struct device *dev, | ||
struct fuel_gauge_set_property *props, | ||
size_t props_len) | ||
{ | ||
struct fuel_gauge_set_property k_props[props_len]; | ||
|
||
Z_OOPS(Z_SYSCALL_DRIVER_FUEL_GAUGE(dev, set_property)); | ||
|
||
Z_OOPS(z_user_from_copy(k_props, props, | ||
props_len * sizeof(struct fuel_gauge_set_property))); | ||
|
||
int ret = z_impl_fuel_gauge_set_prop(dev, k_props, props_len); | ||
|
||
Z_OOPS(z_user_to_copy(props, k_props, props_len * sizeof(struct fuel_gauge_set_property))); | ||
|
||
return ret; | ||
} | ||
|
||
#include <syscalls/fuel_gauge_set_prop_mrsh.c> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Copyright (c) 2023 Google LLC | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
CONFIG_EMUL=y | ||
CONFIG_EMUL_SBS_GAUGE=y | ||
CONFIG_I2C=y | ||
CONFIG_I2C_EMUL=y |
29 changes: 29 additions & 0 deletions
29
tests/drivers/fuel_gauge/sbs_gauge/boards/qemu_arc_hs.overlay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2023 Google LLC | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/dt-bindings/i2c/i2c.h> | ||
|
||
/ { | ||
/* qemu_cortex_a9 board isn't configured with an I2C node */ | ||
fake_i2c_bus: i2c@100 { | ||
status = "okay"; | ||
compatible = "zephyr,i2c-emul-controller"; | ||
clock-frequency = <I2C_BITRATE_STANDARD>; | ||
#address-cells = <1>; | ||
#size-cells = <0>; | ||
reg = <0x100 4>; | ||
}; | ||
}; | ||
|
||
&fake_i2c_bus { | ||
clock-frequency = <I2C_BITRATE_STANDARD>; | ||
compatible = "zephyr,i2c-emul-controller"; | ||
smartbattery0: smartbattery@b { | ||
compatible = "sbs,sbs-gauge-new-api"; | ||
reg = <0x0B>; | ||
status = "okay"; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Copyright (c) 2023 Google LLC | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
CONFIG_EMUL=y | ||
CONFIG_EMUL_SBS_GAUGE=y | ||
CONFIG_I2C=y | ||
CONFIG_I2C_EMUL=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (c) 2023 Google LLC | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/dt-bindings/i2c/i2c.h> | ||
|
||
/ { | ||
/* qemu_cortex_a9 board isn't configured with an I2C node */ | ||
fake_i2c_bus: i2c@100 { | ||
status = "okay"; | ||
compatible = "zephyr,i2c-emul-controller"; | ||
clock-frequency = <I2C_BITRATE_STANDARD>; | ||
#address-cells = <1>; | ||
#size-cells = <0>; | ||
reg = <0x100 4>; | ||
}; | ||
}; | ||
|
||
&fake_i2c_bus { | ||
clock-frequency = <I2C_BITRATE_STANDARD>; | ||
compatible = "zephyr,i2c-emul-controller"; | ||
smartbattery0: smartbattery@b { | ||
compatible = "sbs,sbs-gauge"; | ||
reg = <0x0B>; | ||
status = "okay"; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters