Skip to content

Commit

Permalink
set control terminal mode and add other systemd units
Browse files Browse the repository at this point in the history
  • Loading branch information
Sian Cao committed May 12, 2014
1 parent 92e69f8 commit 7f9e758
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
*.swo
build
*.pyc
log
.zcache
19 changes: 14 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@ include_directories(${FT2_INCLUDE_DIRS})


configure_file(${PROJECT_SOURCE_DIR}/config.h.in ${PROJECT_BINARY_DIR}/config.h)
configure_file(${PROJECT_SOURCE_DIR}/systemd/prometheus-quit.service.in
${PROJECT_BINARY_DIR}/systemd/prometheus-quit.service)

file(GLOB SERVICES RELATIVE ${PROJECT_SOURCE_DIR} "systemd/*.service.in")
message("SERVICES: ${SERVICES}")
foreach(service ${SERVICES})
string(REGEX REPLACE "\\.in$" "" service_dst ${service})
configure_file(${PROJECT_SOURCE_DIR}/${service}
${PROJECT_BINARY_DIR}/${service_dst})
endforeach()

set(SRCS atlas.cc driver.cc glutil.cc options.cc scene.cc)

Expand Down Expand Up @@ -74,6 +80,9 @@ install(FILES initrd/prometheus.initrd_hook
install(FILES initrd/prometheus.initrd_install
DESTINATION lib/initcpio/install RENAME prometheus)
# quit service
install(FILES ${PROJECT_BINARY_DIR}/systemd/prometheus-quit.service
DESTINATION /usr/lib/systemd/system
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
foreach(service ${SERVICES})
string(REGEX REPLACE "\\.in$" "" service_dst ${service})
install(FILES ${PROJECT_BINARY_DIR}/${service_dst}
DESTINATION /usr/lib/systemd/system
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ)
endforeach()
64 changes: 49 additions & 15 deletions driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <signal.h>
#include <termios.h>
#include <linux/kd.h>
#include <linux/vt.h>

#include <iostream>
Expand All @@ -37,6 +38,32 @@ static void err_quit(const char *fmt, ...)
va_end(ap);
}

static map<int, string> vt_modes = {
{KD_GRAPHICS, "graphics"},
{KD_TEXT, "text"},
{KD_TEXT0, "text"},
{KD_TEXT1, "text"},
};

static void set_terminal_mode(int fd, int mode)
{
//TODO: error check
if (dc.vt_mode != mode) {
std::cerr << "switch vt mode to " << vt_modes[mode] << std::endl;
ioctl(dc.vtfd, KDSETMODE, mode);
dc.vt_mode = mode;
}
}

static int get_terminal_mode(int fd)
{
//TODO: error check
int mode = -1;
ioctl(dc.vtfd, KDGETMODE, &mode);
std::cerr << "current vt mode " << vt_modes[mode] << std::endl;
return mode;
}

static void drm_fb_destroy_callback(struct gbm_bo *bo, void *data)
{
uint32_t fb_id = (uint32_t)(unsigned long)data;
Expand Down Expand Up @@ -98,7 +125,7 @@ static void render()

//gettimeofday(&tm_end, NULL);
//float timeval = (tm_end.tv_sec - tm_start.tv_sec) +
//(tm_end.tv_usec - tm_start.tv_usec) / 1000000.0;
//(tm_end.tv_usec - tm_start.tv_usec) / 1000000.0;
//std::cerr << "frame render duration: " << timeval << std::endl;
}

Expand Down Expand Up @@ -161,7 +188,6 @@ static bool handleClientEvent()
}
}


return false;
}

Expand All @@ -177,7 +203,7 @@ static void run_loop()
ev.version = DRM_EVENT_CONTEXT_VERSION;
ev.page_flip_handler = modeset_page_flip_event;
ev.vblank_handler = modeset_vblank_handler;

while (1) {
dc.pflip_pending = true;
render();
Expand Down Expand Up @@ -261,11 +287,14 @@ static void setup_drm()
encoder = drmModeGetEncoder(dc.fd, connector->encoder_id);
if(encoder) {
dc.crtc = encoder->crtc_id;
drmModeCrtc* crtc = drmModeGetCrtc(dc.fd, dc.crtc);
dc.mode = crtc->mode;
drmModeFreeEncoder(encoder);
}
}

if (!encoder) {
std::cerr << "connector has no encoder";
for(i = 0; i < resources->count_encoders; ++i) {
encoder = drmModeGetEncoder(dc.fd,resources->encoders[i]);
if(encoder==0) { continue; }
Expand All @@ -282,11 +311,11 @@ static void setup_drm()
if (i == resources->count_encoders) {
err_quit("No active encoder found!");
}
dc.mode = connector->modes[0];
}

dc.saved_crtc = drmModeGetCrtc(dc.fd, dc.crtc);

dc.mode = connector->modes[0];
printf("\tMode chosen [%s] : Clock => %d, Vertical refresh => %d, Type => %d\n",
dc.mode.name, dc.mode.clock, dc.mode.vrefresh, dc.mode.type);

Expand All @@ -300,8 +329,8 @@ static void setup_egl()
printf("backend name: %s\n", gbm_device_get_backend_name(dc.gbm));

dc.gbm_surface = gbm_surface_create(dc.gbm, dc.mode.hdisplay,
dc.mode.vdisplay, GBM_FORMAT_XRGB8888,
GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
dc.mode.vdisplay, GBM_FORMAT_XRGB8888,
GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
if (!dc.gbm_surface) {
printf("cannot create gbm surface (%d): %m", errno);
exit(-EFAULT);
Expand Down Expand Up @@ -357,8 +386,8 @@ static void setup_egl()
}

dc.surface = eglCreateWindowSurface(dc.display, conf,
(EGLNativeWindowType)dc.gbm_surface,
NULL);
(EGLNativeWindowType)dc.gbm_surface,
NULL);
if (dc.surface == EGL_NO_SURFACE) {
printf("cannot create EGL window surface");
exit(-1);
Expand Down Expand Up @@ -407,6 +436,9 @@ static void setup_vt()

signal(SIGUSR1, on_leave_vt);
signal(SIGUSR2, on_enter_vt);

dc.origin_vt_mode = get_terminal_mode(dc.vtfd);
set_terminal_mode(dc.vtfd, KD_GRAPHICS);
dc.vt_activated = true;
}

Expand Down Expand Up @@ -447,13 +479,15 @@ static void cleanup()
close(dc.commid);
}

if (dc.vtfd > 0)
if (dc.vtfd > 0) {
set_terminal_mode(dc.vtfd, dc.origin_vt_mode);
close(dc.vtfd);
}

drmEventContext ev;
memset(&ev, 0, sizeof(ev));
ev.version = DRM_EVENT_CONTEXT_VERSION;
ev.page_flip_handler = modeset_page_flip_event;
drmEventContext ev;
memset(&ev, 0, sizeof(ev));
ev.version = DRM_EVENT_CONTEXT_VERSION;
ev.page_flip_handler = modeset_page_flip_event;
ev.vblank_handler = modeset_vblank_handler;
std::cerr << "wait for pending page-flip to complete..." << std::endl;
while (dc.pflip_pending) {
Expand All @@ -466,7 +500,7 @@ static void cleanup()
eglDestroySurface(dc.display, dc.surface);
eglDestroyContext(dc.display, dc.gl_context);
eglTerminate(dc.display);

if (dc.bo) {
std::cerr << "destroy bo: " << (unsigned long)dc.bo << std::endl;
gbm_bo_destroy(dc.bo);
Expand Down Expand Up @@ -511,7 +545,7 @@ int main(int argc, char* argv[])
if (!theme.empty())
m->setThemeFile(theme);
dc.action_mode = m;

}
if (!dc.action_mode->init(dc.mode.hdisplay, dc.mode.vdisplay)) {
return -1;
Expand Down
2 changes: 2 additions & 0 deletions driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ struct DisplayContext {
//vt
int vtfd;
bool vt_activated;
int vt_mode; //current mode: graphics or text
int origin_vt_mode;

//communication id
int commid;
Expand Down
9 changes: 9 additions & 0 deletions kdm-prometheus.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=K Display Manager
After=systemd-user-sessions.service prometheus-quit.service

[Service]
ExecStart=/usr/bin/kdm -nodaemon

[Install]
Alias=display-manager.service
10 changes: 10 additions & 0 deletions systemd/prometheus-halt.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Show Prometheus Halt Screen
[email protected]
Before=halt.service
DefaultDependencies=no
ConditionKernelCommandLine=!prometheus.enable=0

[Service]
ExecStart=@CMAKE_INSTALL_PREFIX@/sbin/prometheusd --stage shutdown
Type=forking
10 changes: 10 additions & 0 deletions systemd/prometheus-kexec.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Show Prometheus Reboot with kexec Screen
[email protected]
Before=kexec.service
DefaultDependencies=no
ConditionKernelCommandLine=!prometheus.enable=0

[Service]
ExecStart=@CMAKE_INSTALL_PREFIX@/sbin/prometheusd --stage shutdown
Type=forking
10 changes: 10 additions & 0 deletions systemd/prometheus-poweroff.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Show Prometheus Power Off Screen
[email protected]
Before=poweroff.service
DefaultDependencies=no
ConditionKernelCommandLine=!prometheus.enable=0

[Service]
ExecStart=@CMAKE_INSTALL_PREFIX@/sbin/prometheusd --stage shutdown
Type=forking
10 changes: 10 additions & 0 deletions systemd/prometheus-reboot.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Show Prometheus Reboot Screen
[email protected]
Before=reboot.service
DefaultDependencies=no
ConditionKernelCommandLine=!prometheus.enable=0

[Service]
ExecStart=@CMAKE_INSTALL_PREFIX@/sbin/prometheusd --stage shutdown
Type=forking

0 comments on commit 7f9e758

Please sign in to comment.