static void console_early_suspend(struct early_suspend *h) { #ifdef CONFIG_SHLCDC_BOARD char ev[128]; #endif acquire_console_sem(); orig_fgconsole = fg_console; if (vc_allocate(EARLY_SUSPEND_CONSOLE)) goto err; if (set_console(EARLY_SUSPEND_CONSOLE)) goto err; #ifdef CONFIG_SHLCDC_BOARD vt_waitactive_queue((void *)ev); #endif release_console_sem(); #ifdef CONFIG_SHLCDC_BOARD if (vt_waitactive_wait_dequeue((void *)ev, EARLY_SUSPEND_CONSOLE + 1)) #else if (vt_waitactive(EARLY_SUSPEND_CONSOLE + 1)) #endif pr_warning("console_early_suspend: Can't switch VCs.\n"); return; err: pr_warning("console_early_suspend: Can't set console\n"); release_console_sem(); }
int pm_prepare_console(void) { orig_loglevel = console_loglevel; console_loglevel = new_loglevel; #ifdef SUSPEND_CONSOLE acquire_console_sem(); orig_fgconsole = fg_console; if (vc_allocate(SUSPEND_CONSOLE)) { /* we can't have a free VC for now. Too bad, * we don't want to mess the screen for now. */ release_console_sem(); return 1; } set_console(SUSPEND_CONSOLE); release_console_sem(); if (vt_waitactive(SUSPEND_CONSOLE)) { pr_debug("Suspend: Can't switch VCs."); return 1; } orig_kmsg = kmsg_redirect; kmsg_redirect = SUSPEND_CONSOLE; #endif return 0; }
void pm_restore_console(void) { acquire_console_sem(); if (disable_vt_switch) { release_console_sem(); return; } set_console(orig_fgconsole); release_console_sem(); kmsg_redirect = orig_kmsg; }
/* Hotplug interrupt occurred, read EDID */ static void edid_work_fn(struct work_struct *work) { struct sh_hdmi *hdmi = container_of(work, struct sh_hdmi, edid_work.work); struct sh_mobile_hdmi_info *pdata = hdmi->dev->platform_data; pr_debug("%s(%p): begin, hotplug status %d\n", __func__, pdata->lcd_dev, hdmi->hp_state); if (!pdata->lcd_dev) return; if (hdmi->hp_state == HDMI_HOTPLUG_EDID_DONE) { pm_runtime_get_sync(hdmi->dev); /* A device has been plugged in */ sh_hdmi_read_edid(hdmi); msleep(10); sh_hdmi_configure(hdmi); /* Switched to another (d) power-save mode */ msleep(10); if (!hdmi->info) return; acquire_console_sem(); /* HDMI plug in */ hdmi->info->var = hdmi->var; if (hdmi->info->state != FBINFO_STATE_RUNNING) fb_set_suspend(hdmi->info, 0); else hdmi_display_on(hdmi, hdmi->info); release_console_sem(); } else { if (!hdmi->info) return; acquire_console_sem(); /* HDMI disconnect */ fb_set_suspend(hdmi->info, 1); release_console_sem(); pm_runtime_put(hdmi->dev); } pr_debug("%s(%p): end\n", __func__, pdata->lcd_dev); }
int unregister_console(struct console *console) { struct console *a, *b; int res = 1; acquire_console_sem(); if (console_drivers == console) { console_drivers=console->next; res = 0; } else if (console_drivers) { for (a=console_drivers->next, b=console_drivers ; a; b=a, a=b->next) { if (a == console) { b->next = a->next; res = 0; break; } } } /* If last console is removed, we re-enable picking the first * one that gets registered. Without that, pmac early boot console * would prevent fbcon from taking over. * * If this isn't the last console and it has CON_CONSDEV set, we * need to set it on the next preferred console. */ if (console_drivers == NULL) preferred_console = selected_console; else if (console->flags & CON_CONSDEV) console_drivers->flags |= CON_CONSDEV; release_console_sem(); return res; }
/* * This is printk. It can be called from any context. We want it to work. * * We try to grab the console_sem. If we succeed, it's easy - we log the output and * call the console drivers. If we fail to get the semaphore we place the output * into the log buffer and return. The current holder of the console_sem will * notice the new output in release_console_sem() and will send it to the * consoles before releasing the semaphore. * * One effect of this deferred printing is that code which calls printk() and * then changes console_loglevel may break. This is because console_loglevel * is inspected when the actual printing occurs. */ asmlinkage int printk(const char *fmt, ...) { va_list args; unsigned long flags; int printed_len; char *p; static char printk_buf[1024]; static int log_level_unknown = 1; if (oops_in_progress) { /* If a crash is occurring, make sure we can't deadlock */ spin_lock_init(&logbuf_lock); /* And make sure that we print immediately */ init_MUTEX(&console_sem); } /* This stops the holder of console_sem just where we want him */ spin_lock_irqsave(&logbuf_lock, flags); /* Emit the output into the temporary buffer */ va_start(args, fmt); printed_len = vsnprintf(printk_buf, sizeof(printk_buf), fmt, args); va_end(args); /* * Copy the output into log_buf. If the caller didn't provide * appropriate log level tags, we insert them here */ for (p = printk_buf; *p; p++) { if (log_level_unknown) { if (p[0] != '<' || p[1] < '0' || p[1] > '7' || p[2] != '>') { emit_log_char('<'); emit_log_char(default_message_loglevel + '0'); emit_log_char('>'); } log_level_unknown = 0; } emit_log_char(*p); if (*p == '\n') log_level_unknown = 1; } if (!down_trylock(&console_sem)) { /* * We own the drivers. We can drop the spinlock and let * release_console_sem() print the text */ spin_unlock_irqrestore(&logbuf_lock, flags); console_may_schedule = 0; release_console_sem(); } else { /* * Someone else owns the drivers. We drop the spinlock, which * allows the semaphore holder to proceed and to call the * console drivers with the output which we just produced. */ spin_unlock_irqrestore(&logbuf_lock, flags); } return printed_len; }
static void OMAPLFBDeInitFBDev(OMAPLFB_DEVINFO *psDevInfo) { struct fb_info *psLINFBInfo = psDevInfo->psLINFBInfo; struct module *psLINFBOwner; #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) console_lock(); #else acquire_console_sem(); #endif psLINFBOwner = psLINFBInfo->fbops->owner; if (psLINFBInfo->fbops->fb_release != NULL) { (void) psLINFBInfo->fbops->fb_release(psLINFBInfo, 0); } module_put(psLINFBOwner); #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) console_unlock(); #else release_console_sem(); #endif }
/* Insert the contents of the selection buffer into the * queue of the tty associated with the current console. * Invoked by ioctl(). */ int paste_selection(struct tty_struct *tty) { struct vc_data *vc = (struct vc_data *)tty->driver_data; int pasted = 0; unsigned int count; struct tty_ldisc *ld; DECLARE_WAITQUEUE(wait, current); acquire_console_sem(); poke_blanked_console(); release_console_sem(); ld = tty_ldisc_ref_wait(tty); add_wait_queue(&vc->paste_wait, &wait); while (sel_buffer && sel_buffer_lth > pasted) { set_current_state(TASK_INTERRUPTIBLE); if (test_bit(TTY_THROTTLED, &tty->flags)) { schedule(); continue; } count = sel_buffer_lth - pasted; count = min(count, tty->receive_room); tty->ldisc.receive_buf(tty, sel_buffer + pasted, NULL, count); pasted += count; } remove_wait_queue(&vc->paste_wait, &wait); current->state = TASK_RUNNING; tty_ldisc_deref(ld); return 0; }
static int i915_drm_freeze(struct drm_device *dev) { struct drm_i915_private *dev_priv = dev->dev_private; drm_kms_helper_poll_disable(dev); pci_save_state(dev->pdev); /* If KMS is active, we do the leavevt stuff here */ if (drm_core_check_feature(dev, DRIVER_MODESET)) { int error = i915_gem_idle(dev); if (error) { dev_err(&dev->pdev->dev, "GEM idle failed, resume might fail\n"); return error; } drm_irq_uninstall(dev); } i915_save_state(dev); intel_opregion_fini(dev); /* Modeset on resume, not lid events */ dev_priv->modeset_on_lid = 0; acquire_console_sem(); intel_fbdev_set_suspend(dev, 1); release_console_sem(); return 0; }
int unregister_console(struct console *console) { struct console *a, *b; int res = 1; #ifdef CONFIG_A11Y_BRAILLE_CONSOLE if (console->flags & CON_BRL) return braille_unregister_console(console); #endif acquire_console_sem(); if (console_drivers == console) { console_drivers=console->next; res = 0; } else if (console_drivers) { for (a=console_drivers->next, b=console_drivers ; a; b=a, a=b->next) { if (a == console) { b->next = a->next; res = 0; break; } } } /* * If this isn't the last console and it has CON_CONSDEV set, we * need to set it on the next preferred console. */ if (console_drivers != NULL && console->flags & CON_CONSDEV) console_drivers->flags |= CON_CONSDEV; release_console_sem(); return res; }
static int mxc_elcdif_fb_suspend(struct platform_device *pdev, pm_message_t state) { struct fb_info *fbi = platform_get_drvdata(pdev); struct mxc_elcdif_fb_data *data = (struct mxc_elcdif_fb_data *)fbi->par; int saved_blank; acquire_console_sem(); fb_set_suspend(fbi, 1); saved_blank = data->cur_blank; mxc_elcdif_fb_blank(FB_BLANK_POWERDOWN, fbi); data->next_blank = saved_blank; if (!g_elcdif_pix_clk_enable) { clk_enable(g_elcdif_pix_clk); g_elcdif_pix_clk_enable = true; } mxc_elcdif_stop(); mxc_elcdif_dma_release(); if (g_elcdif_pix_clk_enable) { clk_disable(g_elcdif_pix_clk); g_elcdif_pix_clk_enable = false; } if (g_elcdif_axi_clk_enable) { clk_disable(g_elcdif_axi_clk); g_elcdif_axi_clk_enable = false; } release_console_sem(); return 0; }
int unregister_console(struct console * console) { struct console *a,*b; int res = 1; acquire_console_sem(); if (console_drivers == console) { console_drivers=console->next; res = 0; } else { for (a=console_drivers->next, b=console_drivers ; a; b=a, a=b->next) { if (a == console) { b->next = a->next; res = 0; break; } } } /* If last console is removed, we re-enable picking the first * one that gets registered. Without that, pmac early boot console * would prevent fbcon from taking over. */ if (console_drivers == NULL) preferred_console = selected_console; release_console_sem(); return res; }
void resume_console(void) { if (!console_suspend_enabled) return; console_suspended = 0; release_console_sem(); }
void __pmac register_backlight_controller(struct backlight_controller *ctrler, void *data, char *type) { struct device_node* bk_node; char *prop; int valid = 0; /* There's already a matching controller, bail out */ if (backlighter != NULL) return; bk_node = find_devices("backlight"); #ifdef CONFIG_ADB_PMU /* Special case for the old PowerBook since I can't test on it */ backlight_autosave = machine_is_compatible("AAPL,3400/2400") || machine_is_compatible("AAPL,3500"); if ((backlight_autosave || machine_is_compatible("AAPL,PowerBook1998") || machine_is_compatible("PowerBook1,1")) && !strcmp(type, "pmu")) valid = 1; #endif if (bk_node) { prop = get_property(bk_node, "backlight-control", NULL); if (prop && !strncmp(prop, type, strlen(type))) valid = 1; } if (!valid) return; backlighter = ctrler; backlighter_data = data; if (bk_node && !backlight_autosave) prop = get_property(bk_node, "bklt", NULL); else prop = NULL; if (prop) { backlight_level = ((*prop)+1) >> 1; if (backlight_level > BACKLIGHT_MAX) backlight_level = BACKLIGHT_MAX; } #ifdef CONFIG_ADB_PMU if (backlight_autosave) { struct adb_request req; pmu_request(&req, NULL, 2, 0xd9, 0); while (!req.complete) pmu_poll(); backlight_level = req.reply[0] >> 4; } #endif acquire_console_sem(); if (!backlighter->set_enable(1, backlight_level, data)) backlight_enabled = 1; release_console_sem(); printk(KERN_INFO "Registered \"%s\" backlight controller," "level: %d/15\n", type, backlight_level); }
/* Insert the contents of the selection buffer into the * queue of the tty associated with the current console. * Invoked by ioctl(). */ int paste_selection(struct tty_struct *tty) { struct vt_struct *vt = (struct vt_struct *) tty->driver_data; int pasted = 0, count; DECLARE_WAITQUEUE(wait, current); acquire_console_sem(); poke_blanked_console(); release_console_sem(); add_wait_queue(&vt->paste_wait, &wait); while (sel_buffer && sel_buffer_lth > pasted) { set_current_state(TASK_INTERRUPTIBLE); if (test_bit(TTY_THROTTLED, &tty->flags)) { schedule(); continue; } count = sel_buffer_lth - pasted; count = MIN(count, tty->ldisc.receive_room(tty)); tty->ldisc.receive_buf(tty, sel_buffer + pasted, 0, count); pasted += count; } remove_wait_queue(&vt->paste_wait, &wait); current->state = TASK_RUNNING; return 0; }
static void console_late_resume(struct early_suspend *h) { int ret; #ifdef CONFIG_SHLCDC_BOARD char ev[128]; #endif acquire_console_sem(); ret = set_console(orig_fgconsole); #ifdef CONFIG_SHLCDC_BOARD if (!ret) vt_waitactive_queue((void *)ev); #endif release_console_sem(); if (ret) { pr_warning("console_late_resume: Can't set console.\n"); return; } #ifdef CONFIG_SHLCDC_BOARD if (vt_waitactive_wait_dequeue((void *)ev, orig_fgconsole + 1)) #else if (vt_waitactive(orig_fgconsole + 1)) #endif pr_warning("console_late_resume: Can't switch VCs.\n"); }
static void console_early_suspend(struct early_suspend *h) { acquire_console_sem(); orig_fgconsole = fg_console; if (vc_allocate(EARLY_SUSPEND_CONSOLE)) goto err; if (set_console(EARLY_SUSPEND_CONSOLE)) goto err; release_console_sem(); if (vt_waitactive(EARLY_SUSPEND_CONSOLE)) pr_warning("console_early_suspend: Can't switch VCs.\n"); return; err: pr_warning("console_early_suspend: Can't set console\n"); release_console_sem(); }
void pm_restore_console(void) { acquire_console_sem(); if (disable_vt_switch) { release_console_sem(); return; } set_console(orig_fgconsole); release_console_sem(); if (vt_waitactive(orig_fgconsole)) { pr_debug("Resume: Can't switch VCs."); return; } kmsg_redirect = orig_kmsg; }
static void console_early_suspend(struct early_suspend *h) { printk("[KENEL] %s, %d \n", __FUNCTION__, __LINE__); acquire_console_sem(); orig_fgconsole = fg_console; if (vc_allocate(EARLY_SUSPEND_CONSOLE)) goto err; if (set_console(EARLY_SUSPEND_CONSOLE)) goto err; release_console_sem(); if (vt_waitactive(EARLY_SUSPEND_CONSOLE + 1)) pr_warning("console_early_suspend: Can't switch VCs.\n"); return; err: pr_warning("console_early_suspend: Can't set console\n"); release_console_sem(); }
void console_unblank(void) { struct console *c; acquire_console_sem(); for (c = console_drivers; c != NULL; c = c->next) if ((c->flags & CON_ENABLED) && c->unblank) c->unblank(); release_console_sem(); }
void pm_restore_console(void) { console_loglevel = orig_loglevel; #ifdef SUSPEND_CONSOLE acquire_console_sem(); set_console(orig_fgconsole); release_console_sem(); kmsg_redirect = orig_kmsg; #endif return; }
static int stmfb_resume(struct platform_device *pdev) { struct stmfb_info *i = (struct stmfb_info *)platform_get_drvdata(pdev); DPRINTK("\n"); if(!i) return 0; if(pdev->dev.power.power_state.event == PM_EVENT_ON) return 0; acquire_console_sem(); if(down_interruptible(&i->framebufferLock)) { release_console_sem(); return -EINTR; } if(i->pFBMainOutput) stm_display_output_resume(i->pFBMainOutput); if(i->pFBDVO) stm_display_output_resume(i->pFBDVO); up(&i->framebufferLock); /* * Now the hardware is back, kick the framebuffer into life */ fb_pan_display(&i->info, &i->info.var); fb_set_cmap(&i->info.cmap, &i->info); fb_set_suspend(&i->info, 0); release_console_sem(); DPRINTK("resumed\n"); return 0; }
static int chipsfb_pci_resume(struct pci_dev *pdev) { struct fb_info *p = pci_get_drvdata(pdev); acquire_console_sem(); fb_set_suspend(p, 0); chipsfb_blank(0, p); release_console_sem(); pdev->dev.power.power_state = PMSG_ON; return 0; }
static int mxc_elcdif_fb_resume(struct platform_device *pdev) { struct fb_info *fbi = platform_get_drvdata(pdev); struct mxc_elcdif_fb_data *data = (struct mxc_elcdif_fb_data *)fbi->par; acquire_console_sem(); mxc_elcdif_fb_blank(data->next_blank, fbi); fb_set_suspend(fbi, 0); release_console_sem(); return 0; }
int radeonfb_pci_suspend(struct pci_dev *pdev, u32 state) { struct fb_info *info = pci_get_drvdata(pdev); struct radeonfb_info *rinfo = info->par; /* We don't do anything but D2, for now we return 0, but * we may want to change that. How do we know if the BIOS * can properly take care of D3 ? Also, with swsusp, we * know we'll be rebooted, ... */ printk(KERN_DEBUG "radeonfb: suspending to state: %d...\n", state); acquire_console_sem(); /* Userland should do this but doesn't... bridge gets suspended * too late. Unfortunately, that works only when AGP is built-in, * not for a module. */ #ifdef CONFIG_AGP agp_enable(0); #endif fb_set_suspend(info, 1); if (!radeon_accel_disabled()) { /* Make sure engine is reset */ radeon_engine_idle(); radeonfb_engine_reset(rinfo); radeon_engine_idle(); } /* Blank display and LCD */ radeonfb_blank(VESA_POWERDOWN+1, info); /* Sleep */ rinfo->asleep = 1; rinfo->lock_blank = 1; /* Suspend the chip to D2 state when supported */ #ifdef CONFIG_RADEON_HAS_D2 if (radeon_suspend_to_d2(rinfo, state)) radeon_set_suspend(rinfo, 1); #endif /* CONFIG_RADEON_HAS_D2 */ release_console_sem(); pdev->dev.power_state = state; return 0; }
static void shuttle_flush_console(void) { if (console_flushed) return; console_flushed = true; printk("\n"); pr_emerg("Restarting %s\n", linux_banner); if (!try_acquire_console_sem()) { release_console_sem(); return; } msleep(50); local_irq_disable(); if (try_acquire_console_sem()) pr_emerg("tegra_restart: Console was locked! Busting\n"); else pr_emerg("tegra_restart: Console was locked!\n"); release_console_sem(); }
static int __pmac __set_backlight_enable(int enable) { int rc; if (!backlighter) return -ENODEV; acquire_console_sem(); rc = backlighter->set_enable(enable, backlight_level, backlighter_data); if (!rc) backlight_enabled = enable; release_console_sem(); return rc; }
static void console_late_resume(struct early_suspend *h) { int ret; acquire_console_sem(); ret = set_console(orig_fgconsole); release_console_sem(); if (ret) { pr_warning("console_late_resume: Can't set console.\n"); return; } if (vt_waitactive(orig_fgconsole + 1)) pr_warning("console_late_resume: Can't switch VCs.\n"); }
int pm_prepare_console(void) { acquire_console_sem(); if (disable_vt_switch) { release_console_sem(); return 0; } orig_fgconsole = fg_console; if (vc_allocate(SUSPEND_CONSOLE)) { /* we can't have a free VC for now. Too bad, * we don't want to mess the screen for now. */ release_console_sem(); return 1; } if (set_console(SUSPEND_CONSOLE)) { /* * We're unable to switch to the SUSPEND_CONSOLE. * Let the calling function know so it can decide * what to do. */ release_console_sem(); return 1; } release_console_sem(); if (vt_waitactive(SUSPEND_CONSOLE)) { pr_debug("Suspend: Can't switch VCs."); return 1; } orig_kmsg = kmsg_redirect; kmsg_redirect = SUSPEND_CONSOLE; return 0; }
static void console_early_suspend(struct early_suspend *h) { printk("%s / acquire_console_sem\n", __func__); acquire_console_sem(); orig_fgconsole = fg_console; printk("%s / alloc\n", __func__); if (vc_allocate(EARLY_SUSPEND_CONSOLE)) goto err; printk("%s / set_console\n", __func__); if (set_console(EARLY_SUSPEND_CONSOLE)) goto err; printk("%s / release_console_sem\n", __func__); release_console_sem(); printk("%s / vt_waitactive\n", __func__); if (vt_waitactive(EARLY_SUSPEND_CONSOLE + 1)) pr_warning("console_early_suspend: Can't switch VCs.\n"); printk("%s / end\n", __func__); return; err: pr_warning("console_early_suspend: Can't set console\n"); release_console_sem(); }