drivers/platform/goldfish/goldfish_pipe.c
Source file repositories/reference/linux-study-clean/drivers/platform/goldfish/goldfish_pipe.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/goldfish/goldfish_pipe.c- Extension
.c- Size
- 26635 bytes
- Lines
- 949
- Domain
- Driver Families
- Bucket
- drivers/platform
- 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/module.hlinux/mod_devicetable.hlinux/interrupt.hlinux/kernel.hlinux/spinlock.hlinux/miscdevice.hlinux/platform_device.hlinux/poll.hlinux/sched.hlinux/bitops.hlinux/slab.hlinux/io.hlinux/dma-mapping.hlinux/mm.hlinux/bug.hgoldfish_pipe_qemu.h
Detected Declarations
struct goldfish_pipe_devstruct goldfish_pipe_commandstruct signalled_pipe_bufferstruct open_command_paramstruct goldfish_pipe_dev_buffersstruct goldfish_pipestruct goldfish_pipe_devfunction goldfish_pipe_cmd_lockedfunction goldfish_pipe_cmdfunction goldfish_pipe_error_convertfunction goldfish_pin_pagesfunction populate_rw_paramsfunction transfer_max_buffersfunction wait_for_host_signalfunction goldfish_pipe_read_writefunction goldfish_pipe_readfunction goldfish_pipe_writefunction goldfish_pipe_pollfunction signalled_pipes_add_lockedfunction signalled_pipes_remove_lockedfunction goldfish_interrupt_taskfunction thefunction get_free_pipe_id_lockedfunction goldfish_pipe_openfunction goldfish_pipe_releasefunction init_miscdevicefunction write_pa_addrfunction goldfish_pipe_device_initfunction goldfish_pipe_device_deinitfunction goldfish_pipe_probefunction goldfish_pipe_remove
Annotated Snippet
static const struct file_operations goldfish_pipe_fops = {
.owner = THIS_MODULE,
.read = goldfish_pipe_read,
.write = goldfish_pipe_write,
.poll = goldfish_pipe_poll,
.open = goldfish_pipe_open,
.release = goldfish_pipe_release,
};
static void init_miscdevice(struct miscdevice *miscdev)
{
memset(miscdev, 0, sizeof(*miscdev));
miscdev->minor = MISC_DYNAMIC_MINOR;
miscdev->name = "goldfish_pipe";
miscdev->fops = &goldfish_pipe_fops;
}
static void write_pa_addr(void *addr, void __iomem *portl, void __iomem *porth)
{
const unsigned long paddr = __pa(addr);
writel(upper_32_bits(paddr), porth);
writel(lower_32_bits(paddr), portl);
}
static int goldfish_pipe_device_init(struct platform_device *pdev,
struct goldfish_pipe_dev *dev)
{
int err;
err = devm_request_threaded_irq(&pdev->dev, dev->irq,
goldfish_pipe_interrupt,
goldfish_interrupt_task,
IRQF_SHARED, "goldfish_pipe", dev);
if (err) {
dev_err(&pdev->dev, "unable to allocate IRQ for v2\n");
return err;
}
init_miscdevice(&dev->miscdev);
err = misc_register(&dev->miscdev);
if (err) {
dev_err(&pdev->dev, "unable to register v2 device\n");
return err;
}
dev->pdev_dev = &pdev->dev;
dev->first_signalled_pipe = NULL;
dev->pipes_capacity = INITIAL_PIPES_CAPACITY;
dev->pipes = kzalloc_objs(*dev->pipes, dev->pipes_capacity);
if (!dev->pipes) {
misc_deregister(&dev->miscdev);
return -ENOMEM;
}
/*
* We're going to pass two buffers, open_command_params and
* signalled_pipe_buffers, to the host. This means each of those buffers
* needs to be contained in a single physical page. The easiest choice
* is to just allocate a page and place the buffers in it.
*/
BUILD_BUG_ON(sizeof(struct goldfish_pipe_dev_buffers) > PAGE_SIZE);
dev->buffers = (struct goldfish_pipe_dev_buffers *)
__get_free_page(GFP_KERNEL);
if (!dev->buffers) {
kfree(dev->pipes);
misc_deregister(&dev->miscdev);
return -ENOMEM;
}
/* Send the buffer addresses to the host */
write_pa_addr(&dev->buffers->signalled_pipe_buffers,
dev->base + PIPE_REG_SIGNAL_BUFFER,
dev->base + PIPE_REG_SIGNAL_BUFFER_HIGH);
writel(MAX_SIGNALLED_PIPES,
dev->base + PIPE_REG_SIGNAL_BUFFER_COUNT);
write_pa_addr(&dev->buffers->open_command_params,
dev->base + PIPE_REG_OPEN_BUFFER,
dev->base + PIPE_REG_OPEN_BUFFER_HIGH);
platform_set_drvdata(pdev, dev);
return 0;
}
static void goldfish_pipe_device_deinit(struct platform_device *pdev,
struct goldfish_pipe_dev *dev)
{
Annotation
- Immediate include surface: `linux/module.h`, `linux/mod_devicetable.h`, `linux/interrupt.h`, `linux/kernel.h`, `linux/spinlock.h`, `linux/miscdevice.h`, `linux/platform_device.h`, `linux/poll.h`.
- Detected declarations: `struct goldfish_pipe_dev`, `struct goldfish_pipe_command`, `struct signalled_pipe_buffer`, `struct open_command_param`, `struct goldfish_pipe_dev_buffers`, `struct goldfish_pipe`, `struct goldfish_pipe_dev`, `function goldfish_pipe_cmd_locked`, `function goldfish_pipe_cmd`, `function goldfish_pipe_error_convert`.
- Atlas domain: Driver Families / drivers/platform.
- 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.