28 #include <linux/device.h>
29 #include <linux/errno.h>
37 #include <linux/kernel.h>
40 #include <linux/module.h>
41 #include <linux/slab.h>
42 #include <linux/string.h>
43 #include <linux/types.h>
50 #define AXON_RAM_MODULE_NAME "axonram"
51 #define AXON_RAM_DEVICE_NAME "axonram"
52 #define AXON_RAM_MINORS_PER_DISK 16
53 #define AXON_RAM_BLOCK_SHIFT PAGE_SHIFT
54 #define AXON_RAM_BLOCK_SIZE 1 << AXON_RAM_BLOCK_SHIFT
55 #define AXON_RAM_SECTOR_SHIFT 9
56 #define AXON_RAM_SECTOR_SIZE 1 << AXON_RAM_SECTOR_SHIFT
57 #define AXON_RAM_IRQ_FLAGS IRQF_SHARED | IRQF_TRIGGER_RISING
59 static int azfs_major, azfs_minor;
90 axon_ram_irq_handler(
int irq,
void *
dev)
97 dev_err(&device->
dev,
"Correctable memory error occurred\n");
109 struct axon_ram_bank *bank = bio->bi_bdev->bd_disk->private_data;
110 unsigned long phys_mem, phys_end;
113 unsigned int transfered;
119 bio_for_each_segment(vec, bio, idx) {
120 if (
unlikely(phys_mem + vec->bv_len > phys_end)) {
126 if (bio_data_dir(bio) ==
READ)
127 memcpy(user_mem, (
void *) phys_mem, vec->bv_len);
129 memcpy((
void *) phys_mem, user_mem, vec->bv_len);
131 phys_mem += vec->bv_len;
132 transfered += vec->bv_len;
143 void **kaddr,
unsigned long *pfn)
150 offset += device->
bd_part->start_sect;
152 if (offset >= bank->
size) {
153 dev_err(&bank->
device->dev,
"Access outside of address space\n");
157 *kaddr = (
void *)(bank->
ph_addr + offset);
163 static const struct block_device_operations axon_ram_devops = {
165 .direct_access = axon_ram_direct_access
174 static int axon_ram_bank_id = -1;
181 dev_info(&device->
dev,
"Found memory controller on %s\n",
182 device->
dev.of_node->full_name);
191 device->
dev.platform_data = bank;
196 dev_err(&device->
dev,
"Cannot access device tree\n");
203 if (bank->
size == 0) {
204 dev_err(&device->
dev,
"No DDR2 memory found for %s%d\n",
210 dev_info(&device->
dev,
"Register DDR2 memory device %s%d with %luMB\n",
224 dev_err(&device->
dev,
"Cannot register disk\n");
229 bank->
disk->major = azfs_major;
230 bank->
disk->first_minor = azfs_minor;
231 bank->
disk->fops = &axon_ram_devops;
232 bank->
disk->private_data = bank;
233 bank->
disk->driverfs_dev = &device->
dev;
240 dev_err(&device->
dev,
"Cannot register disk queue\n");
252 dev_err(&device->
dev,
"Cannot access ECC interrupt ID\n");
260 dev_err(&device->
dev,
"Cannot register ECC interrupt handler\n");
268 dev_err(&device->
dev,
"Cannot create sysfs file\n");
273 azfs_minor += bank->
disk->minors;
282 if (bank->
disk->major > 0)
284 bank->
disk->disk_name);
287 device->
dev.platform_data =
NULL;
324 .probe = axon_ram_probe,
325 .remove = axon_ram_remove,
329 .of_match_table = axon_ram_device_id,
340 if (azfs_major < 0) {