drivers/staging/greybus/bootrom.c
Source file repositories/reference/linux-study-clean/drivers/staging/greybus/bootrom.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/staging/greybus/bootrom.c- Extension
.c- Size
- 13608 bytes
- Lines
- 527
- Domain
- Driver Families
- Bucket
- drivers/staging
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/firmware.hlinux/jiffies.hlinux/mutex.hlinux/workqueue.hlinux/greybus.hfirmware.h
Detected Declarations
struct gb_bootromenum next_request_typefunction free_firmwarefunction gb_bootrom_timedoutfunction gb_bootrom_set_timeoutfunction gb_bootrom_cancel_timeoutfunction bootrom_es2_fixup_vid_pidfunction find_firmwarefunction gb_bootrom_firmware_size_requestfunction gb_bootrom_get_firmwarefunction gb_bootrom_ready_to_bootfunction gb_bootrom_request_handlerfunction gb_bootrom_get_versionfunction gb_bootrom_probefunction gb_bootrom_disconnect
Annotated Snippet
struct gb_bootrom {
struct gb_connection *connection;
const struct firmware *fw;
u8 protocol_major;
u8 protocol_minor;
enum next_request_type next_request;
struct delayed_work dwork;
struct mutex mutex; /* Protects bootrom->fw */
};
static void free_firmware(struct gb_bootrom *bootrom)
{
if (!bootrom->fw)
return;
release_firmware(bootrom->fw);
bootrom->fw = NULL;
}
static void gb_bootrom_timedout(struct work_struct *work)
{
struct delayed_work *dwork = to_delayed_work(work);
struct gb_bootrom *bootrom = container_of(dwork,
struct gb_bootrom, dwork);
struct device *dev = &bootrom->connection->bundle->dev;
const char *reason;
switch (bootrom->next_request) {
case NEXT_REQ_FIRMWARE_SIZE:
reason = "Firmware Size Request";
break;
case NEXT_REQ_GET_FIRMWARE:
reason = "Get Firmware Request";
break;
case NEXT_REQ_READY_TO_BOOT:
reason = "Ready to Boot Request";
break;
case NEXT_REQ_MODE_SWITCH:
reason = "Interface Mode Switch";
break;
default:
reason = NULL;
dev_err(dev, "Invalid next-request: %u", bootrom->next_request);
break;
}
dev_err(dev, "Timed out waiting for %s from the Module\n", reason);
mutex_lock(&bootrom->mutex);
free_firmware(bootrom);
mutex_unlock(&bootrom->mutex);
/* TODO: Power-off Module ? */
}
static void gb_bootrom_set_timeout(struct gb_bootrom *bootrom,
enum next_request_type next,
unsigned long timeout)
{
bootrom->next_request = next;
schedule_delayed_work(&bootrom->dwork, msecs_to_jiffies(timeout));
}
static void gb_bootrom_cancel_timeout(struct gb_bootrom *bootrom)
{
cancel_delayed_work_sync(&bootrom->dwork);
}
/*
* The es2 chip doesn't have VID/PID programmed into the hardware and we need to
* hack that up to distinguish different modules and their firmware blobs.
*
* This fetches VID/PID (over bootrom protocol) for es2 chip only, when VID/PID
* already sent during hotplug are 0.
*
* Otherwise, we keep intf->vendor_id/product_id same as what's passed
* during hotplug.
*/
static void bootrom_es2_fixup_vid_pid(struct gb_bootrom *bootrom)
{
struct gb_bootrom_get_vid_pid_response response;
struct gb_connection *connection = bootrom->connection;
struct gb_interface *intf = connection->bundle->intf;
int ret;
if (!(intf->quirks & GB_INTERFACE_QUIRK_NO_GMP_IDS))
return;
ret = gb_operation_sync(connection, GB_BOOTROM_TYPE_GET_VID_PID,
NULL, 0, &response, sizeof(response));
Annotation
- Immediate include surface: `linux/firmware.h`, `linux/jiffies.h`, `linux/mutex.h`, `linux/workqueue.h`, `linux/greybus.h`, `firmware.h`.
- Detected declarations: `struct gb_bootrom`, `enum next_request_type`, `function free_firmware`, `function gb_bootrom_timedout`, `function gb_bootrom_set_timeout`, `function gb_bootrom_cancel_timeout`, `function bootrom_es2_fixup_vid_pid`, `function find_firmware`, `function gb_bootrom_firmware_size_request`, `function gb_bootrom_get_firmware`.
- Atlas domain: Driver Families / drivers/staging.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.