mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2025-01-15 11:47:47 +00:00
71 lines
1.9 KiB
C
71 lines
1.9 KiB
C
|
// SPDX-License-Identifier: GPL-2.0-only
|
||
|
// Copyright (C) 2022 Linutronix GmbH, John Ogness
|
||
|
// Copyright (C) 2022 Intel, Thomas Gleixner
|
||
|
|
||
|
#include <linux/kernel.h>
|
||
|
#include <linux/console.h>
|
||
|
#include "internal.h"
|
||
|
/*
|
||
|
* Printk console printing implementation for consoles which does not depend
|
||
|
* on the legacy style console_lock mechanism.
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* nbcon_state_set - Helper function to set the console state
|
||
|
* @con: Console to update
|
||
|
* @new: The new state to write
|
||
|
*
|
||
|
* Only to be used when the console is not yet or no longer visible in the
|
||
|
* system. Otherwise use nbcon_state_try_cmpxchg().
|
||
|
*/
|
||
|
static inline void nbcon_state_set(struct console *con, struct nbcon_state *new)
|
||
|
{
|
||
|
atomic_set(&ACCESS_PRIVATE(con, nbcon_state), new->atom);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* nbcon_state_read - Helper function to read the console state
|
||
|
* @con: Console to read
|
||
|
* @state: The state to store the result
|
||
|
*/
|
||
|
static inline void nbcon_state_read(struct console *con, struct nbcon_state *state)
|
||
|
{
|
||
|
state->atom = atomic_read(&ACCESS_PRIVATE(con, nbcon_state));
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* nbcon_state_try_cmpxchg() - Helper function for atomic_try_cmpxchg() on console state
|
||
|
* @con: Console to update
|
||
|
* @cur: Old/expected state
|
||
|
* @new: New state
|
||
|
*
|
||
|
* Return: True on success. False on fail and @cur is updated.
|
||
|
*/
|
||
|
static inline bool nbcon_state_try_cmpxchg(struct console *con, struct nbcon_state *cur,
|
||
|
struct nbcon_state *new)
|
||
|
{
|
||
|
return atomic_try_cmpxchg(&ACCESS_PRIVATE(con, nbcon_state), &cur->atom, new->atom);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* nbcon_init - Initialize the nbcon console specific data
|
||
|
* @con: Console to initialize
|
||
|
*/
|
||
|
void nbcon_init(struct console *con)
|
||
|
{
|
||
|
struct nbcon_state state = { };
|
||
|
|
||
|
nbcon_state_set(con, &state);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* nbcon_cleanup - Cleanup the nbcon console specific data
|
||
|
* @con: Console to cleanup
|
||
|
*/
|
||
|
void nbcon_cleanup(struct console *con)
|
||
|
{
|
||
|
struct nbcon_state state = { };
|
||
|
|
||
|
nbcon_state_set(con, &state);
|
||
|
}
|