ECE 440 · Week 4

Modern Computer: Full Stack

What a bind line looks like in the kernel log, and which job stays in userspace.

Week 4 of 10 · Solitude

ECE 440 · Week 4 · In class

What a bind line looks like in the kernel log, and which job stays in userspace.

ECE 440 · Week 4 · In class

A bind line is the kernel log line that names your module and the device it attached to.

ECE 440 · Week 4 · Lecture

How a driver meets its device

ECE 440 · Week 4 · Lecture

The smallest platform driver

static const struct of_device_id mydev_ids[] = {
	{ .compatible = "vendor,mydev" },
	{ }
};
MODULE_DEVICE_TABLE(of, mydev_ids);

static struct platform_driver mydev_driver = {
	.probe  = mydev_probe,
	.driver = {
		.name = "mydev",
		.of_match_table = mydev_ids,
	},
};
module_platform_driver(mydev_driver);

ECE 440 · Week 4 · Lecture

probe(): map the registers, read one

static int mydev_probe(struct platform_device *pdev)
{
	void __iomem *base;
	u32 val;

	base = devm_platform_ioremap_resource(pdev, 0);
	if (IS_ERR(base))
		return PTR_ERR(base);

	val = readl(base);
	dev_info(&pdev->dev, "bound, reg0=0x%08x\n", val);
	return 0;
}

ECE 440 · Week 4 · Lecture

Reading the bind line

ECE 440 · Week 4 · Lecture

What stays in userspace

Kernel driverUserspace program
Maps registers, handles interruptsDecides what to do with the data
Exposes a device node or a sysfs fileOpens that node and reads or writes it
A bug can take the whole board downA bug ends one process

Put in the kernel only what needs the hardware or its timing.

ECE 440 · Week 4 · Lab

Lab

  1. Write and load a kernel module that binds to the week-2 node and reads one register from the device.
  2. Name one job that stays in userspace. Second pass: unload the module and load it once more, and keep the second bind line in your notes.
  3. Assemble the lab hand-in: The kernel module source, the bind line from the kernel log, and one sentence naming a job that stays in userspace.

ECE 440 · Week 4 · Lab

Hand in

The kernel module source, the bind line from the kernel log, and one sentence naming a job that stays in userspace.

ECE 440 · Week 4 · Homework

Homework

ECE 440 · Week 4 · Homework

Turn in

Those two names.

ECE 440 · Week 4 · Read

Read

On the lab site: Module 11, Drivers. This week grades your module, the bind line, and the userspace sentence.

ECE 440 · Week 4 · Next

Week 5

Boot time and input power are a pair.

Arrow keys or space to move, F for full screen, N for speaker notes, Home and End for the first and last slide. Print gives one slide per page.