STRUCT COMEDI_DEVICE(9)
π struct comedi_device(9) β the Kernel API Manual moment π
okay so bestie, gather round, because today we're talking about struct comedi_device β which is described in the Kernel API Manual, and it's literally the working data for a COMEDI device. main character struct energy, no cap. π
β¨ NAME β¨
struct comedi_device β the working data for a COMEDI device. that's it, that's the vibe. π¦
πΈ SYNOPSIS πΈ
here's the whole glow-up, copy it exactly bestie, every single member matters:
struct comedi_device {
int use_count;
struct comedi_driver *driver;
struct comedi_8254 *pacer;
void *private;
struct device *class_dev;
int minor;
unsigned int detach_count;
struct device *hw_dev;
const char *board_name;
const void *board_ptr;
unsigned int attached:1;
unsigned int ioenabled:1;
spinlock_t spinlock;
struct mutex mutex;
struct rw_semaphore attach_lock;
struct kref refcount;
int n_subdevices;
struct comedi_subdevice *subdevices;
void __iomem *mmio;
unsigned long iobase;
unsigned long iolen;
unsigned int irq;
struct comedi_subdevice *read_subdev;
struct comedi_subdevice *write_subdev;
struct fasync_struct *async_queue;
int (*open)(struct comedi_device *dev);
void (*close)(struct comedi_device *dev);
int (*insn_device_config)(struct comedi_device *dev, struct
comedi_insn *insn, unsigned int *data);
unsigned int (*get_valid_routes)(struct comedi_device *dev, unsigned
int n_pairs, unsigned int *pair_data);
};
yes the wrapping on those last two function pointers is exactly like that in the original, don't come for me π
π§© Members π§©
okay this is the part where we go member by member, like a group chat roll call. every single one gets its moment. π
use_countβ the number of open file objects. that's the whole job. counting the opens. πdriverβ the low-level COMEDI driver attached to this COMEDI device. your ride-or-die.pacerβ an optional pointer to a dynamically allocated acquisition pacer control. it gets freed automatically after the COMEDI device is detached from the low-level driver, so likeβ¦ don't stress about the cleanup, it handles itself. π§privateβ an optional pointer to private data allocated by the low-level driver. same deal: freed automatically after the COMEDI device is detached from the low-level driver. self-cleaning icon.class_devβ the sysfscomediXdevice. hi bestie, you're in sysfs now.minorβ the minor device number of the COMEDI char device (0-47). yes, 0 through 47, those are the numbers, memorize them.detach_countβ a counter, incremented every time the COMEDI device is detached. it's used for checking that a previous attachment is still valid. like a receipt for your last breakup, lowkey.hw_devβ an optional pointer to the low-level hardwarestruct device. and now the important part, bestie, read carefully: it's required for automatically configured COMEDI devices, and optional for COMEDI devices configured by theCOMEDI_DEVCONFIGioctl β although the bus-specific COMEDI functions only work if it is set correctly. it's also passed todma_alloc_coherentfor COMEDI subdevices that have their'async_dma_dir'member set to something other thanDMA_NONE. so many jobs, one pointer, fr fr.board_nameβ a pointer to a COMEDI board name or a COMEDI driver name. the deets: when the low-level driver's"attach"handler is called by the handler for theCOMEDI_DEVCONFIGioctl, it either points to a matched board name string if the'num_names'member of thestruct comedi_driveris non-zero, otherwise it points to the low-level driver name string. when the low-lever driver's"auto_attach"handler is called for an automatically configured COMEDI device, it points to the low-level driver name string. the low-level driver is free to change it in its"attach"or"auto_attach"handler if it wishes. (yes, "low-lever" β that's a typo that lives in the original, I'm not fixing it, I'm not that kind of girl π)board_ptrβ an optional pointer to private, read-only board type information in the low-level driver. if the'num_names'member of thestruct comedi_driveris non-zero, the handler for theCOMEDI_DEVCONFIGioctl will point it to a pointer to a matched board name string within the driver's private array of static, read-only board type information when calling the driver's"attach"handler. the low-level driver is free to change it. so much freedom, honestly iconic. π¦attachedβ a flag indicating that the COMEDI device is attached to a low-level driver. are we attached? yes we are.ioenabledβ a flag used to indicate that a PCI device has been enabled and its regions requested. slay, get those regions.spinlockβ a generic spin-lock for use by the low-level driver. spin spin spin. π₯mutexβ a generic mutex for use by the COMEDI core module. mutual exclusion, mutual respect.attach_lockβ astruct rw_semaphoreused to guard against the COMEDI device being detached while an operation is in progress. thedown_writeoperation is only allowed whilemutexis held, and is used when changingattachedanddetach_countand calling the low-level driver's"detach"handler. thedown_readoperation is generally used without holdingmutex. that's the rule bestie, boundaries are healthy.refcountβ astruct krefreference counter for freeing the COMEDI device. it's giving responsible memory management.n_subdevicesβ the number of COMEDI subdevices allocated by the low-level driver for this device. count them.subdevicesβ a dynamically allocated array of COMEDI subdevices. the whole squad, allocated. π«Άmmioβ an optional pointer to a remapped MMIO region, set by the low-level driver. πiobaseβ an optional base of an I/O port region requested by the low-level driver.iolenβ the length of the I/O port region requested atiobase. they're a package deal, iykyk.irqβ an optional IRQ number requested by the low-level driver.read_subdevβ an optional pointer to a default COMEDI subdevice operated on by the read file operation. set by the low-level driver. the reader. the main character of read(). πwrite_subdevβ an optional pointer to a default COMEDI subdevice operated on by the write file operation. set by the low-level driver. the writer. equally iconic.async_queueβ storage forfasync_helper. just storage. humble. holding it down.openβ an optional pointer to a function set by the low-level driver, called whenuse_countchanges from0to1. the "hi we're here" moment.closeβ an optional pointer to a function set by the low-level driver, called whenuse_countchanged from1to0. the "ok bye ily" moment. πinsn_device_configβ an optional pointer to a handler for all sub-instructions exceptINSN_DEVICE_CONFIG_GET_ROUTESof theINSN_DEVICE_CONFIGinstruction. if this is not initialized by the low-level driver, a default handler will be set during post-configuration. the core has your back, bestie.get_valid_routesβ an optional pointer to a handler for theINSN_DEVICE_CONFIG_GET_ROUTESsub-instruction of theINSN_DEVICE_CONFIGinstruction set. if this is not initialized by the low-level driver, a default handler that copies zero routes back to the user will be used. zero routes. none. empty. π
π Description π
so here's the tea: this is the main control data structure for a COMEDI device (as far as the COMEDI core is concerned). like, the core's whole understanding of the device lives here. π
there are two groups of COMEDI devices, and you need to know both, okay?
- "legacy" devices β configured by the handler for the
COMEDI_DEVCONFIGioctl. these are allocated during module initialization if the"comedi_num_legacy_minors"module parameter is non-zero, and they use minor device numbers from0tocomedi_num_legacy_minorsminus one. - automatically configured devices β resulting from a call to
comedi_auto_configas a result of a bus driver probe in a low-level COMEDI driver. these are allocated on demand and use minor device numbers fromcomedi_num_legacy_minorsto47.
so: legacy = allocated at module init, minor numbers 0 to comedi_num_legacy_minors minus one. auto = allocated on demand, minor numbers comedi_num_legacy_minors to 47. both groups, both ranges, memorized. periodt. β
π¦ SEE ALSO π¦
the whole friend group, every single one tagged, no one left out:
- the kernel file
./include/linux/comedi/comedidev.h struct comedi_subdevice(9)struct comedi_buf_page(9)struct comedi_buf_map(9)struct comedi_async(9)enum comedi_cb(9)struct comedi_driver(9)struct comedi_lrange(9)comedi_range_is_bipolar(9)comedi_range_is_unipolar(9)comedi_range_is_external(9)comedi_chan_range_is_bipolar(9)comedi_chan_range_is_unipolar(9)comedi_chan_range_is_external(9)comedi_offset_munge(9)comedi_bytes_per_sample(9)comedi_sample_shift(9)comedi_bytes_to_samples(9)comedi_samples_to_bytes(9)comedi_check_trigger_src(9)comedi_check_trigger_is_unique(9)comedi_check_trigger_arg_is(9)comedi_check_trigger_arg_min(9)comedi_check_trigger_arg_max(9)comedi_buf_n_bytes_ready(9)__comedi_request_region(9)comedi_request_region(9)module_comedi_driver(9)
ngl bestie, if you got all the way here you officially understand struct comedi_device better than most people. go drink some water. π
and that's a wrap! this came from ./include/linux/comedi, dated October 2026, and yes, the page name is struct comedi_device(9) β mwah, bye, ily, slay πβ¨π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms