arch/mips/txx9/generic/setup.c

Source file repositories/reference/linux-study-clean/arch/mips/txx9/generic/setup.c

File Facts

System
Linux kernel
Corpus path
arch/mips/txx9/generic/setup.c
Extension
.c
Size
20248 bytes
Lines
856
Domain
Architecture Layer
Bucket
arch/mips
Inferred role
Architecture Layer: operation-table or driver-model contract
Status
pattern implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

static const struct bus_type txx9_sramc_subsys = {
	.name = "txx9_sram",
	.dev_name = "txx9_sram",
};

struct txx9_sramc_dev {
	struct device dev;
	struct bin_attribute bindata_attr;
	void __iomem *base;
};

static ssize_t txx9_sram_read(struct file *filp, struct kobject *kobj,
			      const struct bin_attribute *bin_attr,
			      char *buf, loff_t pos, size_t size)
{
	struct txx9_sramc_dev *dev = bin_attr->private;
	size_t ramsize = bin_attr->size;

	if (pos >= ramsize)
		return 0;
	if (pos + size > ramsize)
		size = ramsize - pos;
	memcpy_fromio(buf, dev->base + pos, size);
	return size;
}

static ssize_t txx9_sram_write(struct file *filp, struct kobject *kobj,
			       const struct bin_attribute *bin_attr,
			       char *buf, loff_t pos, size_t size)
{
	struct txx9_sramc_dev *dev = bin_attr->private;
	size_t ramsize = bin_attr->size;

	if (pos >= ramsize)
		return 0;
	if (pos + size > ramsize)
		size = ramsize - pos;
	memcpy_toio(dev->base + pos, buf, size);
	return size;
}

static void txx9_device_release(struct device *dev)
{
	struct txx9_sramc_dev *tdev;

	tdev = container_of(dev, struct txx9_sramc_dev, dev);
	kfree(tdev);
}

void __init txx9_sramc_init(struct resource *r)
{
	struct txx9_sramc_dev *dev;
	size_t size;
	int err;

	err = subsys_system_register(&txx9_sramc_subsys, NULL);
	if (err)
		return;
	dev = kzalloc_obj(*dev);
	if (!dev)
		return;
	size = resource_size(r);
	dev->base = ioremap(r->start, size);
	if (!dev->base) {
		kfree(dev);
		return;
	}
	dev->dev.release = &txx9_device_release;
	dev->dev.bus = &txx9_sramc_subsys;
	sysfs_bin_attr_init(&dev->bindata_attr);
	dev->bindata_attr.attr.name = "bindata";
	dev->bindata_attr.attr.mode = S_IRUSR | S_IWUSR;
	dev->bindata_attr.read = txx9_sram_read;
	dev->bindata_attr.write = txx9_sram_write;
	dev->bindata_attr.size = size;
	dev->bindata_attr.private = dev;
	err = device_register(&dev->dev);
	if (err)
		goto exit_put;
	err = sysfs_create_bin_file(&dev->dev.kobj, &dev->bindata_attr);
	if (err) {
		iounmap(dev->base);
		device_unregister(&dev->dev);
	}
	return;
exit_put:
	iounmap(dev->base);
	put_device(&dev->dev);
}

Annotation

Implementation Notes