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

Ship ec_sys as a dkms module for Debian #205

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
## How to install
### Package or not package ?
- If you are using archlinux or a derivative you can install it from AUR: ```yay -S isw```
- If you are using debian or a derivate:
- Clone ```git clone https://github.com/YoyPa/isw```
- Install build tools for packaging ```apt install build-essential devscripts```
- Build the package ```debuild -us -uc -b```
- Install it ```apt install ../isw_*.deb```
- If you are on a different distro family:
- Clone ```git clone https://github.com/YoyPa/isw```
- Then look at this <a href="https://aur.archlinux.org/cgit/aur.git/tree/PKGBUILD?h=isw">PKGBUILD</a> to know where to put files.
Expand Down
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
isw (1.10-2) unstable; urgency=medium

* Ship ec_sys as a dkms module

-- Jose Angel Pastrana Padilla <[email protected]> Sun, 08 Aug 2021 10:45:29 +0200

isw (1.10-1) unstable; urgency=medium

* Release 1.10
Expand Down
4 changes: 2 additions & 2 deletions debian/control
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Source: isw
Section: unknown
Section: admin
Priority: optional
Maintainer: Hayden Hughes <[email protected]>
Build-Depends: debhelper-compat (= 12)
Build-Depends: debhelper-compat (= 13)
Standards-Version: 4.4.0
Homepage: https://github.com/YoyPa/isw

Expand Down
1 change: 1 addition & 0 deletions debian/isw.dkms
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dkms/dkms.conf
2 changes: 1 addition & 1 deletion debian/isw.install
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
etc
usr/lib/systemd/system/[email protected] lib/systemd/system
isw usr/bin
dkms/* usr/src/isw-${env:DEB_VERSION}
12 changes: 6 additions & 6 deletions debian/postinst → debian/isw.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,15 @@ set -e
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

case "$1" in
configure)
modprobe ec_sys write_support=1
rmmod ec_sys 2>/dev/null || true
modprobe -v ec_sys || true
;;

abort-upgrade|abort-remove|abort-deconfigure)
Expand All @@ -32,9 +37,4 @@ case "$1" in
;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
38 changes: 38 additions & 0 deletions debian/isw.prerm
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh
# prerm script for isw
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
# * <prerm> `remove'
# * <old-prerm> `upgrade' <new-version>
# * <new-prerm> `failed-upgrade' <old-version>
# * <conflictor's-prerm> `remove' `in-favour' <package> <new-version>
# * <deconfigured's-prerm> `deconfigure' `in-favour'
# <package-being-installed> <version> `removing'
# <conflicting-package> <version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

case "$1" in
remove|upgrade|deconfigure)
rmmod ec_sys 2>/dev/null || true
;;

failed-upgrade)
;;

*)
echo "postinst called with unknown argument \`$1'" >&2
exit 1
;;
esac

exit 0
1 change: 1 addition & 0 deletions debian/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
usr/lib/systemd/system/[email protected]
30 changes: 13 additions & 17 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1


# see FEATURE AREAS in dpkg-buildflags(1)
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
# package maintainers to append LDFLAGS
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
#DH_VERBOSE = 1

# see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/*
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk
export DEB_VERSION

# main packaging script based on dh7 syntax
%:
dh $@

dh $@ --with dkms

# dh_make generated override targets
# This is example for Cmake (See https://bugs.debian.org/641051 )
#override_dh_auto_configure:
# dh_auto_configure -- # -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)
# put upstream version for dkms module
override_dh_dkms:
dh_dkms -V $(DEB_VERSION)

# do not start or enable it on install
override_dh_installsystemd:
dh_installsystemd --no-start --no-enable
38 changes: 38 additions & 0 deletions dkms/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/make -f

MODULES := ec_sys

reverse = $(if $(1),$(call reverse,$(wordlist 2,$(words $(1)),$(1)))) $(firstword $(1))
REVMODS := $(call reverse,$(MODULES))

all: $(MODULES)

$(MODULES):
$(MAKE) -C "$@"

CLEANMODS := $(addprefix clean-,$(MODULES))
$(CLEANMODS):
$(MAKE) -C "$(subst clean-,,$@)" clean
clean: $(CLEANMODS)

LOADMODS := $(addprefix load-,$(MODULES))
$(LOADMODS):
$(MAKE) -C "$(subst load-,,$@)" load
load: $(LOADMODS)

UNLOADMODS := $(addprefix unload-,$(REVMODS))
$(UNLOADMODS):
$(MAKE) -C "$(subst unload-,,$@)" unload
unload: $(UNLOADMODS)

INSTALLMODS := $(addprefix install-,$(MODULES))
$(INSTALLMODS):
$(MAKE) -C "$(subst install-,,$@)" install
install: $(INSTALLMODS)

UNINSTALLMODS := $(addprefix uninstall-,$(REVMODS))
$(UNINSTALLMODS):
$(MAKE) -C "$(subst uninstall-,,$@)" uninstall
uninstall: $(UNINSTALLMODS)

.PHONY: all clean $(MODULES) $(CLEANMODS) $(LOADMODS) $(UNLOADMODS) $(INSTALLMODS) $(UNINSTALLMODS)
21 changes: 21 additions & 0 deletions dkms/dkms.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
PACKAGE_NAME="isw"
PACKAGE_VERSION="#MODULE_VERSION#"
MAKE[0]="make KVER=${kernelver} KDIR=${kernel_source_dir} -C ${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build"
CLEAN="make KVER=${kernelver} KDIR=${kernel_source_dir} -C ${dkms_tree}/${PACKAGE_NAME}/${PACKAGE_VERSION}/build clean"
BUILT_MODULE_NAME[0]="ec_sys"
BUILT_MODULE_LOCATION[0]="ec_sys/"
DEST_MODULE_LOCATION[0]="/extra"
AUTOINSTALL="yes"
REMAKE_INITRD="no"

# Don't build module when ACPI is disabled
if ! grep -q "^CONFIG_ACPI=[ym]$" "$kernel_source_dir/.config" 2>/dev/null ; then
echo "ACPI disabled in this kernel, not building module." >&2
BUILD_EXCLUSIVE_ARCH="^do_not_build$"
fi

# Don't build module when EC_DEBUGFS is already compiled
if grep -q "^CONFIG_ACPI_EC_DEBUGFS=[ym]$" "$kernel_source_dir/.config" 2>/dev/null ; then
echo "ACPI is present in this kernel, not building module." >&2
BUILD_EXCLUSIVE_ARCH="^do_not_build$"
fi
28 changes: 28 additions & 0 deletions dkms/ec_sys/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
obj-m := ec_sys.o

ifndef KVER
KVER := $(shell uname -r)
endif
ifndef KDIR
KDIR := /lib/modules/$(KVER)/build
endif

PWD := $(shell pwd)

default:
$(MAKE) -C $(KDIR) M=$(PWD) modules

clean:
$(MAKE) -C $(KDIR) M=$(PWD) clean

install:
$(MAKE) -C $(KDIR) M=$(PWD) modules_install

uninstall:
$(MAKE) -C $(KDIR) M=$(PWD) modules_uninstall

load:
insmod ec_sys.ko

unload:
-rmmod ec_sys
144 changes: 144 additions & 0 deletions dkms/ec_sys/ec_sys.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* ec_sys.c
*
* Copyright (C) 2010 SUSE Products GmbH/Novell
* Author:
* Thomas Renninger <[email protected]>
*/

#include <linux/kernel.h>
#include <linux/acpi.h>
#include <linux/debugfs.h>
#include <linux/module.h>
#include <linux/uaccess.h>
#include "internal.h"

MODULE_AUTHOR("Thomas Renninger <[email protected]>");
MODULE_DESCRIPTION("ACPI EC sysfs access driver");
MODULE_LICENSE("GPL");

static bool write_support;
module_param(write_support, bool, 0644);
MODULE_PARM_DESC(write_support, "Dangerous, reboot and removal of battery may "
"be needed.");

#define EC_SPACE_SIZE 256

static struct dentry *acpi_ec_debugfs_dir;

static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
size_t count, loff_t *off)
{
/* Use this if support reading/writing multiple ECs exists in ec.c:
* struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
*/
unsigned int size = EC_SPACE_SIZE;
loff_t init_off = *off;
int err = 0;

if (*off >= size)
return 0;
if (*off + count >= size) {
size -= *off;
count = size;
} else
size = count;

while (size) {
u8 byte_read;
err = ec_read(*off, &byte_read);
if (err)
return err;
if (put_user(byte_read, buf + *off - init_off)) {
if (*off - init_off)
return *off - init_off; /* partial read */
return -EFAULT;
}
*off += 1;
size--;
}
return count;
}

static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
size_t count, loff_t *off)
{
/* Use this if support reading/writing multiple ECs exists in ec.c:
* struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
*/

unsigned int size = count;
loff_t init_off = *off;
int err = 0;

if (!write_support)
return -EINVAL;

if (*off >= EC_SPACE_SIZE)
return 0;
if (*off + count >= EC_SPACE_SIZE) {
size = EC_SPACE_SIZE - *off;
count = size;
}

while (size) {
u8 byte_write;
if (get_user(byte_write, buf + *off - init_off)) {
if (*off - init_off)
return *off - init_off; /* partial write */
return -EFAULT;
}
err = ec_write(*off, byte_write);
if (err)
return err;

*off += 1;
size--;
}
return count;
}

static const struct file_operations acpi_ec_io_ops = {
.owner = THIS_MODULE,
.open = simple_open,
.read = acpi_ec_read_io,
.write = acpi_ec_write_io,
.llseek = default_llseek,
};

static void acpi_ec_add_debugfs(struct acpi_ec *ec, unsigned int ec_device_count)
{
struct dentry *dev_dir;
char name[64];
umode_t mode = 0400;

if (ec_device_count == 0)
acpi_ec_debugfs_dir = debugfs_create_dir("ec", NULL);

sprintf(name, "ec%u", ec_device_count);
dev_dir = debugfs_create_dir(name, acpi_ec_debugfs_dir);

debugfs_create_x32("gpe", 0444, dev_dir, &first_ec->gpe);
debugfs_create_bool("use_global_lock", 0444, dev_dir,
&first_ec->global_lock);

if (write_support)
mode = 0600;
debugfs_create_file("io", mode, dev_dir, ec, &acpi_ec_io_ops);
}

static int __init acpi_ec_sys_init(void)
{
if (first_ec)
acpi_ec_add_debugfs(first_ec, 0);
return 0;
}

static void __exit acpi_ec_sys_exit(void)
{
debugfs_remove_recursive(acpi_ec_debugfs_dir);
}

module_init(acpi_ec_sys_init);
module_exit(acpi_ec_sys_exit);
Loading