drivers/platform/x86/ibm_rtl.c

Source file repositories/reference/linux-study-clean/drivers/platform/x86/ibm_rtl.c

File Facts

System
Linux kernel
Corpus path
drivers/platform/x86/ibm_rtl.c
Extension
.c
Size
7877 bytes
Lines
326
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.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct bus_type rtl_subsys = {
	.name = "ibm_rtl",
	.dev_name = "ibm_rtl",
};

static DEVICE_ATTR(version, S_IRUGO, rtl_show_version, NULL);
static DEVICE_ATTR(state, 0600, rtl_show_state, rtl_set_state);

static struct device_attribute *rtl_attributes[] = {
	&dev_attr_version,
	&dev_attr_state,
	NULL
};


static int rtl_setup_sysfs(void) {
	int ret, i;

	ret = subsys_system_register(&rtl_subsys, NULL);
	if (!ret) {
		struct device *dev_root = bus_get_dev_root(&rtl_subsys);

		if (dev_root) {
			for (i = 0; rtl_attributes[i]; i ++)
				device_create_file(dev_root, rtl_attributes[i]);
			put_device(dev_root);
		}
	}
	return ret;
}

static void rtl_teardown_sysfs(void) {
	struct device *dev_root = bus_get_dev_root(&rtl_subsys);
	int i;

	if (dev_root) {
		for (i = 0; rtl_attributes[i]; i ++)
			device_remove_file(dev_root, rtl_attributes[i]);
		put_device(dev_root);
	}
	bus_unregister(&rtl_subsys);
}


static const struct dmi_system_id ibm_rtl_dmi_table[] __initconst = {
	{                                                  \
		.matches = {                               \
			DMI_MATCH(DMI_SYS_VENDOR, "IBM"),  \
		},                                         \
	},
	{ }
};

static int __init ibm_rtl_init(void) {
	unsigned long ebda_addr, ebda_size;
	unsigned int ebda_kb;
	int ret = -ENODEV, i;

	if (force)
		pr_warn("module loaded by force\n");
	/* first ensure that we are running on IBM HW */
	else if (efi_enabled(EFI_BOOT) || !dmi_check_system(ibm_rtl_dmi_table))
		return -ENODEV;

	/* Get the address for the Extended BIOS Data Area */
	ebda_addr = get_bios_ebda();
	if (!ebda_addr) {
		RTL_DEBUG("no BIOS EBDA found\n");
		return -ENODEV;
	}

	ebda_map = ioremap(ebda_addr, 4);
	if (!ebda_map)
		return -ENOMEM;

	/* First word in the EDBA is the Size in KB */
	ebda_kb = ioread16(ebda_map);
	RTL_DEBUG("EBDA is %d kB\n", ebda_kb);

	if (ebda_kb == 0)
		goto out;

	iounmap(ebda_map);
	ebda_size = ebda_kb*1024;

	/* Remap the whole table */
	ebda_map = ioremap(ebda_addr, ebda_size);
	if (!ebda_map)
		return -ENOMEM;

Annotation

Implementation Notes