Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

interfaces: add pwm-control interface #12347

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zyga
Copy link
Collaborator

@zyga zyga commented Nov 23, 2022

The pwm-control interface is similar in spirit to the gpio-control interface, allowing access to any and all pulse-width-modulation channels.

The interface is equally privileged. The only difference as compared to GPIO control is the set of permissions granted. Those are modeled after the kernel documentation referenced from a code comment.

Signed-off-by: Zygmunt Krynicki me@zygoon.pl

@zyga zyga force-pushed the feature/pwm-control branch 2 times, most recently from a28c237 to 5e3bc4c Compare November 23, 2022 17:56
@bboozzoo bboozzoo requested a review from mvo5 November 23, 2022 18:00
@bboozzoo bboozzoo added the Needs security review Can only be merged once security gave a :+1: label Nov 23, 2022
@zyga
Copy link
Collaborator Author

zyga commented Nov 23, 2022

@degville shall I write a documentation snippet about this interface on the forum?

@mardy
Copy link
Contributor

mardy commented Nov 23, 2022

I just had a quick look, and my main question is what are the cases that the existing pwm interface does not cover. I see that that interface is for a single pwm per plug, but one could specify mode plugs if one needs more than one PWM. Then indeed, unless I'm mistaken, with this new interface one could enumerate and access all pwms in the system without an a priori knowledge of how many of them there are, whereas in the other interface one would just get what one asks for.

@zyga
Copy link
Collaborator Author

zyga commented Nov 23, 2022

@mardy the relation between the (so far missing) pwm-control and pwm is the same as between gpio-contrl (existing) and gpio. It mainly depends on how the application was written to being with. If the app is in control of PWM on the system and wants to manage it manually, you need a -control style interface.

@degville
Copy link
Contributor

@degville shall I write a documentation snippet about this interface on the forum?

Yes please! I'll edit it there if needed. I think it's great to see usernames attached to the work they're responsible for.

Copy link
Contributor

@mardy mardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but since this is a new interface I think we need @pedronis 's review as well :-)

@mardy mardy added the Needs Samuele review Needs a review from Samuele before it can land label Nov 28, 2022
@pedronis pedronis self-requested a review November 29, 2022 09:15
Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, as parallel to gpio-control for PWM this looks fine to me


/sys/class/pwm/pwmchip[0-9]*/{,un}export rw,
/sys/class/pwm/pwmchip[0-9]*/npwm r,
/sys/class/pwm/pwmchip[0-9]*/pwm[0-9]*/{period,duty_cycle,polarity,enable} rw,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afaict pwm itself, used /* for the last component here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can adjust that. I just wanted to be precise, as it is easier to extend but harder to take the permissions away.

If you want I can change that to the general glob.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but given the choice for pwm itself, I think it's better to be consistent at this point, also it would be strange for the -control variant to be more restricted in this way than the non-control one

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, I'll send an update in a moment.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pedronis done. I have also added the k permission to match the pwm interface better (k allows locking AFAIR).

@zyga
Copy link
Collaborator Author

zyga commented Nov 30, 2022

@degville shall I write a documentation snippet about this interface on the forum?

Yes please! I'll edit it there if needed. I think it's great to see usernames attached to the work they're responsible for.

I've created https://forum.snapcraft.io/t/the-pwm-control-interface/32908 based on the documentation of the gpio-control interface.

I think both interfaces could use some technical details. I'll do another round of proposed updates to those threads to see what you think @degville

EDIT: I think the sort of thing now present on under the "developer details" section of the PWM interface is what I was thinking of.

The pwm-control interface is similar in spirit to the gpio-control
interface, allowing access to any and all pulse-width-modulation
channels.

The interface is equally privileged. The only difference as compared to
GPIO control is the set of permissions granted. Those are modeled after
the kernel documentation referenced from a code comment.

Signed-off-by: Zygmunt Krynicki <me@zygoon.pl>
Copy link
Collaborator

@alexmurray alexmurray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@alexmurray alexmurray removed the Needs security review Can only be merged once security gave a :+1: label Dec 1, 2022
@zyga
Copy link
Collaborator Author

zyga commented Dec 2, 2022

Please hold on with merging this. I had to apply one more change for this to really work.

I totally missed the fact that sysfs is full of symlinks. I made a change that looks almost identical to what pwm does, just with a glob. I'll clean it up and send for re-review.

@zyga
Copy link
Collaborator Author

zyga commented Dec 9, 2022

I'll pick this up mid next week. I have an urgent thing to address outside of the scope of snapd.

@zyga
Copy link
Collaborator Author

zyga commented Dec 14, 2022

I still have a few things to do but I will push an update with the new look of the code for possible feedback.

# potentially impact the system and other snaps, and allows privileged access
# to hardware.

/sys/class/pwm/pwmchip[0-9]*/{,un}export rw,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The three patterns look good, but fail on the symlink:

On a random Raspberry Pi 5:

zyga@pi5-1:/sys/class/pwm$ ls -ld pwmchip*
lrwxrwxrwx 1 root root 0 Nov  8 18:38 pwmchip0 -> ../../devices/platform/axi/1000120000.pcie/1f0009c000.pwm/pwm/pwmchip0
lrwxrwxrwx 1 root root 0 Feb  6 23:48 pwmchip4 -> ../../devices/platform/soc/107d517a80.pwm/pwm/pwmchip4

So this pattern alone would not work.

@ernestl ernestl requested a review from mardy February 27, 2024 23:15
@zyga zyga removed the Needs Samuele review Needs a review from Samuele before it can land label Mar 7, 2024
@zyga
Copy link
Collaborator Author

zyga commented Mar 7, 2024

This needs re-design to avoid the problem of symlinks and apparmor.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants