drivers/tty/hvc/hvcs.c
Source file repositories/reference/linux-study-clean/drivers/tty/hvc/hvcs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/tty/hvc/hvcs.c- Extension
.c- Size
- 43925 bytes
- Lines
- 1546
- Domain
- Driver Families
- Bucket
- drivers/tty
- Inferred role
- Driver Families: operation-table or driver-model contract
- Status
- pattern implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/init.hlinux/completion.hlinux/interrupt.hlinux/kernel.hlinux/kref.hlinux/kthread.hlinux/list.hlinux/major.hlinux/module.hlinux/moduleparam.hlinux/sched.hlinux/slab.hlinux/spinlock.hlinux/stat.hlinux/tty.hlinux/tty_flip.hasm/hvconsole.hasm/hvcserver.hlinux/uaccess.hlinux/termios_internal.hasm/vio.h
Detected Declarations
struct hvcs_structfunction hvcs_partner_vtys_showfunction hvcs_partner_clcs_showfunction hvcs_current_vty_storefunction hvcs_current_vty_showfunction hvcs_vterm_state_storefunction hvcs_vterm_state_showfunction hvcs_index_showfunction rescan_showfunction rescan_storefunction hvcs_kickfunction hvcs_unthrottlefunction hvcs_throttlefunction hvcs_handle_interruptfunction hvcs_try_writefunction hvcs_iofunction khvcsdfunction list_for_each_entryfunction hvcs_return_indexfunction hvcs_destruct_portfunction hvcs_get_indexfunction hvcs_probefunction hvcs_removefunction hvcs_set_pifunction hvcs_get_pifunction hvcs_rescan_devices_listfunction list_for_each_entryfunction hvcs_has_pifunction hvcs_partner_connectfunction hvcs_partner_freefunction hvcs_enable_devicefunction hvcs_installfunction hvcs_openfunction hvcs_closefunction hvcs_cleanupfunction hvcs_hangupfunction hvcs_removefunction hvcs_write_roomfunction hvcs_chars_in_bufferfunction hvcs_alloc_index_listfunction hvcs_free_index_listfunction hvcs_initializefunction hvcs_module_initfunction hvcs_module_exitmodule init hvcs_module_init
Annotated Snippet
static ssize_t rescan_show(struct device_driver *ddp, char *buf)
{
/* A 1 means it is updating, a 0 means it is done updating */
return snprintf(buf, PAGE_SIZE, "%d\n", hvcs_rescan_status);
}
static ssize_t rescan_store(struct device_driver *ddp, const char * buf,
size_t count)
{
if ((simple_strtol(buf, NULL, 0) != 1)
&& (hvcs_rescan_status != 0))
return -EINVAL;
hvcs_rescan_status = 1;
printk(KERN_INFO "HVCS: rescanning partner info for all"
" vty-servers.\n");
hvcs_rescan_devices_list();
hvcs_rescan_status = 0;
return count;
}
static DRIVER_ATTR_RW(rescan);
static struct attribute *hvcs_attrs[] = {
&driver_attr_rescan.attr,
NULL,
};
ATTRIBUTE_GROUPS(hvcs);
static void hvcs_kick(void)
{
hvcs_kicked = 1;
wmb();
wake_up_process(hvcs_task);
}
static void hvcs_unthrottle(struct tty_struct *tty)
{
struct hvcs_struct *hvcsd = tty->driver_data;
unsigned long flags;
spin_lock_irqsave(&hvcsd->lock, flags);
hvcsd->todo_mask |= HVCS_SCHED_READ;
spin_unlock_irqrestore(&hvcsd->lock, flags);
hvcs_kick();
}
static void hvcs_throttle(struct tty_struct *tty)
{
struct hvcs_struct *hvcsd = tty->driver_data;
unsigned long flags;
spin_lock_irqsave(&hvcsd->lock, flags);
vio_disable_interrupts(hvcsd->vdev);
spin_unlock_irqrestore(&hvcsd->lock, flags);
}
/*
* If the device is being removed we don't have to worry about this interrupt
* handler taking any further interrupts because they are disabled which means
* the hvcs_struct will always be valid in this handler.
*/
static irqreturn_t hvcs_handle_interrupt(int irq, void *dev_instance)
{
struct hvcs_struct *hvcsd = dev_instance;
spin_lock(&hvcsd->lock);
vio_disable_interrupts(hvcsd->vdev);
hvcsd->todo_mask |= HVCS_SCHED_READ;
spin_unlock(&hvcsd->lock);
hvcs_kick();
return IRQ_HANDLED;
}
/* This function must be called with the hvcsd->lock held */
static void hvcs_try_write(struct hvcs_struct *hvcsd)
{
uint32_t unit_address = hvcsd->vdev->unit_address;
struct tty_struct *tty = hvcsd->port.tty;
int sent;
if (hvcsd->todo_mask & HVCS_TRY_WRITE) {
/* won't send partial writes */
sent = hvc_put_chars(unit_address,
&hvcsd->buffer[0],
hvcsd->chars_in_buffer );
if (sent > 0) {
hvcsd->chars_in_buffer = 0;
Annotation
- Immediate include surface: `linux/device.h`, `linux/init.h`, `linux/completion.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/kref.h`, `linux/kthread.h`, `linux/list.h`.
- Detected declarations: `struct hvcs_struct`, `function hvcs_partner_vtys_show`, `function hvcs_partner_clcs_show`, `function hvcs_current_vty_store`, `function hvcs_current_vty_show`, `function hvcs_vterm_state_store`, `function hvcs_vterm_state_show`, `function hvcs_index_show`, `function rescan_show`, `function rescan_store`.
- Atlas domain: Driver Families / drivers/tty.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.