arch/um/drivers/port_kern.c
Source file repositories/reference/linux-study-clean/arch/um/drivers/port_kern.c
File Facts
- System
- Linux kernel
- Corpus path
arch/um/drivers/port_kern.c- Extension
.c- Size
- 6668 bytes
- Lines
- 306
- Domain
- Architecture Layer
- Bucket
- arch/um
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- 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/completion.hlinux/interrupt.hlinux/list.hlinux/mutex.hlinux/slab.hlinux/workqueue.hasm/atomic.hinit.hirq_kern.hos.hport.h
Detected Declarations
struct port_liststruct port_devstruct connectionfunction pipe_interruptfunction port_acceptfunction port_work_procfunction port_interruptfunction port_waitfunction port_remove_devfunction port_kern_freefunction free_portfunction list_for_each
Annotated Snippet
struct port_list {
struct list_head list;
atomic_t wait_count;
int has_connection;
struct completion done;
int port;
int fd;
spinlock_t lock;
struct list_head pending;
struct list_head connections;
};
struct port_dev {
struct port_list *port;
int helper_pid;
int telnetd_pid;
};
struct connection {
struct list_head list;
int fd;
int helper_pid;
int socket[2];
int telnetd_pid;
struct port_list *port;
};
static irqreturn_t pipe_interrupt(int irq, void *data)
{
struct connection *conn = data;
int n_fds = 1, fd = -1;
ssize_t ret;
ret = os_rcv_fd_msg(conn->socket[0], &fd, n_fds, &conn->helper_pid,
sizeof(conn->helper_pid));
if (ret != sizeof(conn->helper_pid)) {
if (ret == -EAGAIN)
return IRQ_NONE;
printk(KERN_ERR "pipe_interrupt : os_rcv_fd_msg returned %zd\n",
ret);
os_close_file(conn->fd);
}
list_del(&conn->list);
conn->fd = fd;
list_add(&conn->list, &conn->port->connections);
complete(&conn->port->done);
return IRQ_HANDLED;
}
#define NO_WAITER_MSG \
"****\n" \
"There are currently no UML consoles waiting for port connections.\n" \
"Either disconnect from one to make it available or activate some more\n" \
"by enabling more consoles in the UML /etc/inittab.\n" \
"****\n"
static int port_accept(struct port_list *port)
{
struct connection *conn;
int fd, socket[2], pid;
fd = port_connection(port->fd, socket, &pid);
if (fd < 0) {
if (fd != -EAGAIN)
printk(KERN_ERR "port_accept : port_connection "
"returned %d\n", -fd);
goto out;
}
conn = kmalloc_obj(*conn, GFP_ATOMIC);
if (conn == NULL) {
printk(KERN_ERR "port_accept : failed to allocate "
"connection\n");
goto out_close;
}
*conn = ((struct connection)
{ .list = LIST_HEAD_INIT(conn->list),
.fd = fd,
.socket = { socket[0], socket[1] },
.telnetd_pid = pid,
.port = port });
if (um_request_irq(TELNETD_IRQ, socket[0], IRQ_READ, pipe_interrupt,
IRQF_SHARED, "telnetd", conn) < 0) {
printk(KERN_ERR "port_accept : failed to get IRQ for "
"telnetd\n");
Annotation
- Immediate include surface: `linux/completion.h`, `linux/interrupt.h`, `linux/list.h`, `linux/mutex.h`, `linux/slab.h`, `linux/workqueue.h`, `asm/atomic.h`, `init.h`.
- Detected declarations: `struct port_list`, `struct port_dev`, `struct connection`, `function pipe_interrupt`, `function port_accept`, `function port_work_proc`, `function port_interrupt`, `function port_wait`, `function port_remove_dev`, `function port_kern_free`.
- Atlas domain: Architecture Layer / arch/um.
- Implementation status: source 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.