-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rtc translator and RTC CMOS driver
A /hurd/rtc translator will be created as, users can create a /dev/rtc device using the following command: ``` sudo settrans -c /dev/rtc /hurd/rtc ``` * Makefile: add rtc-cmos server into the compile chain * hurd/pioctl.defs: new file. Interfaces for rtc ioctl operations * hurd/rtc.h: new file. Interfaces for rtc device * rtc/Makefile: new file. Makefile for rtc server * rtc/main.c: new file. Initialisation for rtc translator * rtc/mig-mutate.h: new file. Type translation for rtc server * rtc/rtc-cmos_pioctl-ops.c: new file. The rtc-cmos server-side implementation Signed-off-by: Zhaoming Luo <[email protected]> Message-ID: <[email protected]>
- Loading branch information
Showing
7 changed files
with
555 additions
and
1 deletion.
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
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,59 @@ | ||
/* Definitions for /dev/rtc ioctls | ||
|
||
Copyright (C) 2024 Free Software Foundation, Inc. | ||
|
||
This file is part of the GNU Hurd. | ||
|
||
The GNU Hurd is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License as | ||
published by the Free Software Foundation; either version 2, or (at | ||
your option) any later version. | ||
|
||
The GNU Hurd is distributed in the hope that it will be useful, but | ||
WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
General Public License for more details. | ||
|
||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ | ||
|
||
/* Ioctl group 'p'; the subsystem is derived from calculations in | ||
hurd/ioctls.defs. */ | ||
subsystem pioctl 140000; | ||
|
||
#include <hurd/ioctl_types.defs> | ||
|
||
import <hurd/rtc.h>; | ||
|
||
#ifdef PIOCTL_IMPORTS | ||
PIOCTL_IMPORTS | ||
#endif | ||
|
||
INTR_INTERFACE | ||
|
||
/* This is the arg for a struct rtc_time as specified by the | ||
definition of _IOT_rtc_time in $(hurd)/hurd/rtc.h. */ | ||
type rtc_time_t = struct[9] of int; | ||
|
||
skip; skip; skip; /* 0 1 2 */ | ||
|
||
/* 3 RTC_UIE_ON */ | ||
routine pioctl_rtc_uie_on ( | ||
reqport: io_t); | ||
|
||
/* 4 RTC_UIE_OFF */ | ||
routine pioctl_rtc_uie_off ( | ||
reqport: io_t); | ||
|
||
skip; skip; skip; skip; /* 5 6 7 8 */ | ||
|
||
/* 9 RTC_RD_TIME */ | ||
routine pioctl_rtc_rd_time ( | ||
reqport: io_t; | ||
out tm: rtc_time_t); | ||
|
||
/* 10 RTC_SET_TIME */ | ||
routine pioctl_rtc_set_time ( | ||
reqport: io_t; | ||
tm: rtc_time_t); |
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,51 @@ | ||
/* GNU Hurd RTC interface | ||
Copyright (C) 2024 Free Software Foundation, Inc. | ||
This file is part of the GNU Hurd. | ||
The GNU Hurd is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License as | ||
published by the Free Software Foundation; either version 2, or (at | ||
your option) any later version. | ||
The GNU Hurd is distributed in the hope that it will be useful, but | ||
WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ | ||
|
||
#ifndef _RTC_H | ||
#define _RTC_H 1 | ||
|
||
#include <hurd/ioctl.h> | ||
|
||
struct rtc_time | ||
{ | ||
int tm_sec; | ||
int tm_min; | ||
int tm_hour; | ||
int tm_mday; | ||
int tm_mon; | ||
int tm_year; | ||
int tm_wday; | ||
int tm_yday; | ||
int tm_isdst; | ||
}; | ||
typedef struct rtc_time rtc_time_t; | ||
|
||
#define _IOT_rtc_time _IOT(_IOTS(int),9,0,0,0,0) | ||
|
||
/* ioctl calls that are permitted to the /dev/rtc interface, if | ||
any of the RTC drivers are enabled. */ | ||
|
||
#define RTC_UIE_ON _IO('p', 0x03) /* Update int. enable on. */ | ||
#define RTC_UIE_OFF _IO('p', 0x04) /* ... off. */ | ||
|
||
#define RTC_RD_TIME _IOR('p', 0x09, struct rtc_time) /* Read RTC time. */ | ||
#define RTC_SET_TIME _IOW('p', 0x0a, struct rtc_time) /* Set RTC time. */ | ||
|
||
#endif /* rtc.h */ |
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,39 @@ | ||
# Makefile for rtc server | ||
# | ||
# Copyright (C) 2024 Free Software Foundation, Inc. | ||
# | ||
# This file is part of the GNU Hurd. | ||
# | ||
# The GNU Hurd is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License as | ||
# published by the Free Software Foundation; either version 2, or (at | ||
# your option) any later version. | ||
# | ||
# The GNU Hurd is distributed in the hope that it will be useful, but | ||
# WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ | ||
|
||
dir := rtc | ||
makemode := server | ||
|
||
SRCS = main.c rtc-cmos_pioctl-ops.c | ||
MIGSRCS = pioctlServer.c | ||
|
||
OBJS = main.o pioctlServer.o rtc-cmos_pioctl-ops.o | ||
|
||
HURDLIBS = trivfs shouldbeinlibc ports | ||
|
||
target = rtc | ||
|
||
include ../Makeconf | ||
|
||
MIGCOMSFLAGS += -prefix rtc_ | ||
mig-sheader-prefix = rtc_ | ||
pioctl-MIGSFLAGS = -imacros $(srcdir)/mig-mutate.h | ||
|
||
rtc_pioctl_S.h pioctlServer.c: mig-mutate.h |
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,104 @@ | ||
/* A translator for accessing rtc | ||
Copyright (C) 2024 Free Software Foundation, Inc. | ||
This file is part of the GNU Hurd. | ||
The GNU Hurd is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License as | ||
published by the Free Software Foundation; either version 2, or (at | ||
your option) any later version. | ||
The GNU Hurd is distributed in the hope that it will be useful, but | ||
WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ | ||
|
||
#include <version.h> | ||
|
||
#include <error.h> | ||
#include <stdbool.h> | ||
#include <argp.h> | ||
#include <hurd/trivfs.h> | ||
#include <hurd/ports.h> | ||
#include <hurd/rtc.h> | ||
#include <sys/io.h> | ||
|
||
#include "rtc_pioctl_S.h" | ||
|
||
const char *argp_program_version = STANDARD_HURD_VERSION (rtc); | ||
|
||
static struct trivfs_control *rtccntl; | ||
|
||
int trivfs_fstype = FSTYPE_DEV; | ||
int trivfs_fsid = 0; | ||
int trivfs_support_read = 1; | ||
int trivfs_support_write = 0; | ||
int trivfs_support_exec = 0; | ||
int trivfs_allow_open = O_READ | O_WRITE; | ||
|
||
static const struct argp rtc_argp = | ||
{ NULL, NULL, NULL, "Real-Time Clock device" }; | ||
|
||
static int | ||
demuxer (mach_msg_header_t *inp, mach_msg_header_t *outp) | ||
{ | ||
mig_routine_t routine; | ||
if ((routine = rtc_pioctl_server_routine (inp)) || | ||
(routine = NULL, trivfs_demuxer (inp, outp))) | ||
{ | ||
if (routine) | ||
(*routine) (inp, outp); | ||
return TRUE; | ||
} | ||
else | ||
return FALSE; | ||
} | ||
|
||
int | ||
main (int argc, char **argv) | ||
{ | ||
error_t err; | ||
mach_port_t bootstrap; | ||
|
||
argp_parse (&rtc_argp, argc, argv, 0, 0, 0); | ||
|
||
task_get_bootstrap_port (mach_task_self (), &bootstrap); | ||
if (bootstrap == MACH_PORT_NULL) | ||
error (1, 0, "Must be started as a translator"); | ||
|
||
/* Request for permission to do i/o on port numbers 0x70 and 0x71 for | ||
accessing RTC registers. Do this before replying to our parent, so | ||
we don't end up saying "I'm ready!" and then immediately exit with | ||
an error. */ | ||
err = ioperm (0x70, 2, true); | ||
if (err) | ||
error (1, err, "Request IO permission failed"); | ||
|
||
/* Reply to our parent. */ | ||
err = trivfs_startup (bootstrap, O_NORW, NULL, NULL, NULL, NULL, &rtccntl); | ||
mach_port_deallocate (mach_task_self (), bootstrap); | ||
if (err) | ||
error (1, err, "trivfs_startup failed"); | ||
|
||
/* Launch. */ | ||
ports_manage_port_operations_one_thread (rtccntl->pi.bucket, demuxer, | ||
2 * 60 * 1000); | ||
|
||
return 0; | ||
} | ||
|
||
void | ||
trivfs_modify_stat (struct trivfs_protid *cred, struct stat *st) | ||
{ | ||
} | ||
|
||
error_t | ||
trivfs_goaway (struct trivfs_control *fsys, int flags) | ||
{ | ||
exit (EXIT_SUCCESS); | ||
} |
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,24 @@ | ||
/* Type translation for rtc operations | ||
Copyright (C) 2024 Free Software Foundation, Inc. | ||
This file is part of the GNU Hurd. | ||
The GNU Hurd is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License as | ||
published by the Free Software Foundation; either version 2, or (at | ||
your option) any later version. | ||
The GNU Hurd is distributed in the hope that it will be useful, but | ||
WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ | ||
|
||
#define IO_INTRAN trivfs_protid_t trivfs_begin_using_protid (io_t) | ||
#define IO_INTRAN_PAYLOAD trivfs_protid_t trivfs_begin_using_protid_payload | ||
#define IO_DESTRUCTOR trivfs_end_using_protid (trivfs_protid_t) | ||
#define PIOCTL_IMPORTS import "../libtrivfs/mig-decls.h"; |
Oops, something went wrong.