Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright IBM Deutschland Entwicklung GmbH 2006 |
| 3 | * |
| 4 | * Author: Maxim Shchetynin <maxim@de.ibm.com> |
| 5 | * |
| 6 | * Axon DDR2 device driver. |
| 7 | * It registers one block device per Axon's DDR2 memory bank found on a system. |
| 8 | * Block devices are called axonram?, their major and minor numbers are |
| 9 | * available in /proc/devices, /proc/partitions or in /sys/block/axonram?/dev. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2, or (at your option) |
| 14 | * any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 24 | */ |
| 25 | |
| 26 | #include <linux/bio.h> |
| 27 | #include <linux/blkdev.h> |
Dan Williams | 60fcd55 | 2017-01-25 15:25:11 -0800 | [diff] [blame] | 28 | #include <linux/dax.h> |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 29 | #include <linux/device.h> |
| 30 | #include <linux/errno.h> |
| 31 | #include <linux/fs.h> |
| 32 | #include <linux/genhd.h> |
| 33 | #include <linux/interrupt.h> |
| 34 | #include <linux/io.h> |
| 35 | #include <linux/ioport.h> |
| 36 | #include <linux/irq.h> |
| 37 | #include <linux/irqreturn.h> |
| 38 | #include <linux/kernel.h> |
| 39 | #include <linux/mm.h> |
| 40 | #include <linux/mod_devicetable.h> |
| 41 | #include <linux/module.h> |
| 42 | #include <linux/slab.h> |
| 43 | #include <linux/string.h> |
| 44 | #include <linux/types.h> |
Jon Loeliger | eb8f276 | 2007-11-14 04:13:09 +1100 | [diff] [blame] | 45 | #include <linux/of_device.h> |
| 46 | #include <linux/of_platform.h> |
Dan Williams | 34c0fd5 | 2016-01-15 16:56:14 -0800 | [diff] [blame] | 47 | #include <linux/pfn_t.h> |
Jon Loeliger | eb8f276 | 2007-11-14 04:13:09 +1100 | [diff] [blame] | 48 | |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 49 | #include <asm/page.h> |
| 50 | #include <asm/prom.h> |
| 51 | |
| 52 | #define AXON_RAM_MODULE_NAME "axonram" |
| 53 | #define AXON_RAM_DEVICE_NAME "axonram" |
| 54 | #define AXON_RAM_MINORS_PER_DISK 16 |
| 55 | #define AXON_RAM_BLOCK_SHIFT PAGE_SHIFT |
| 56 | #define AXON_RAM_BLOCK_SIZE 1 << AXON_RAM_BLOCK_SHIFT |
| 57 | #define AXON_RAM_SECTOR_SHIFT 9 |
| 58 | #define AXON_RAM_SECTOR_SIZE 1 << AXON_RAM_SECTOR_SHIFT |
| 59 | #define AXON_RAM_IRQ_FLAGS IRQF_SHARED | IRQF_TRIGGER_RISING |
| 60 | |
Maxim Shchetynin | 9a23409 | 2008-07-16 05:51:41 +1000 | [diff] [blame] | 61 | static int azfs_major, azfs_minor; |
| 62 | |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 63 | struct axon_ram_bank { |
Grant Likely | a454dc5 | 2010-07-22 15:52:34 -0600 | [diff] [blame] | 64 | struct platform_device *device; |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 65 | struct gendisk *disk; |
Dan Williams | 60fcd55 | 2017-01-25 15:25:11 -0800 | [diff] [blame] | 66 | struct dax_device *dax_dev; |
Maxim Shchetynin | fedcd2c | 2007-08-23 03:01:27 +1000 | [diff] [blame] | 67 | unsigned int irq_id; |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 68 | unsigned long ph_addr; |
| 69 | unsigned long io_addr; |
| 70 | unsigned long size; |
| 71 | unsigned long ecc_counter; |
| 72 | }; |
| 73 | |
| 74 | static ssize_t |
| 75 | axon_ram_sysfs_ecc(struct device *dev, struct device_attribute *attr, char *buf) |
| 76 | { |
Grant Likely | a454dc5 | 2010-07-22 15:52:34 -0600 | [diff] [blame] | 77 | struct platform_device *device = to_platform_device(dev); |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 78 | struct axon_ram_bank *bank = device->dev.platform_data; |
| 79 | |
| 80 | BUG_ON(!bank); |
| 81 | |
| 82 | return sprintf(buf, "%ld\n", bank->ecc_counter); |
| 83 | } |
| 84 | |
| 85 | static DEVICE_ATTR(ecc, S_IRUGO, axon_ram_sysfs_ecc, NULL); |
| 86 | |
| 87 | /** |
| 88 | * axon_ram_irq_handler - interrupt handler for Axon RAM ECC |
| 89 | * @irq: interrupt ID |
| 90 | * @dev: pointer to of_device |
| 91 | */ |
| 92 | static irqreturn_t |
| 93 | axon_ram_irq_handler(int irq, void *dev) |
| 94 | { |
Grant Likely | a454dc5 | 2010-07-22 15:52:34 -0600 | [diff] [blame] | 95 | struct platform_device *device = dev; |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 96 | struct axon_ram_bank *bank = device->dev.platform_data; |
| 97 | |
| 98 | BUG_ON(!bank); |
| 99 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 100 | dev_err(&device->dev, "Correctable memory error occurred\n"); |
Maxim Shchetynin | fedcd2c | 2007-08-23 03:01:27 +1000 | [diff] [blame] | 101 | bank->ecc_counter++; |
| 102 | return IRQ_HANDLED; |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /** |
| 106 | * axon_ram_make_request - make_request() method for block device |
| 107 | * @queue, @bio: see blk_queue_make_request() |
| 108 | */ |
Jens Axboe | dece163 | 2015-11-05 10:41:16 -0700 | [diff] [blame] | 109 | static blk_qc_t |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 110 | axon_ram_make_request(struct request_queue *queue, struct bio *bio) |
| 111 | { |
| 112 | struct axon_ram_bank *bank = bio->bi_bdev->bd_disk->private_data; |
| 113 | unsigned long phys_mem, phys_end; |
| 114 | void *user_mem; |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 115 | struct bio_vec vec; |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 116 | unsigned int transfered; |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 117 | struct bvec_iter iter; |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 118 | |
Kent Overstreet | 4f024f3 | 2013-10-11 15:44:27 -0700 | [diff] [blame] | 119 | phys_mem = bank->io_addr + (bio->bi_iter.bi_sector << |
| 120 | AXON_RAM_SECTOR_SHIFT); |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 121 | phys_end = bank->io_addr + bank->size; |
| 122 | transfered = 0; |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 123 | bio_for_each_segment(vec, bio, iter) { |
| 124 | if (unlikely(phys_mem + vec.bv_len > phys_end)) { |
Al Viro | d81fec0 | 2007-10-12 07:00:19 +0100 | [diff] [blame] | 125 | bio_io_error(bio); |
Jens Axboe | dece163 | 2015-11-05 10:41:16 -0700 | [diff] [blame] | 126 | return BLK_QC_T_NONE; |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 127 | } |
| 128 | |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 129 | user_mem = page_address(vec.bv_page) + vec.bv_offset; |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 130 | if (bio_data_dir(bio) == READ) |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 131 | memcpy(user_mem, (void *) phys_mem, vec.bv_len); |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 132 | else |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 133 | memcpy((void *) phys_mem, user_mem, vec.bv_len); |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 134 | |
Kent Overstreet | 7988613 | 2013-11-23 17:19:00 -0800 | [diff] [blame] | 135 | phys_mem += vec.bv_len; |
| 136 | transfered += vec.bv_len; |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 137 | } |
Christoph Hellwig | 4246a0b | 2015-07-20 15:29:37 +0200 | [diff] [blame] | 138 | bio_endio(bio); |
Jens Axboe | dece163 | 2015-11-05 10:41:16 -0700 | [diff] [blame] | 139 | return BLK_QC_T_NONE; |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 140 | } |
| 141 | |
Dan Williams | d4b29fd7 | 2017-01-27 17:22:03 -0800 | [diff] [blame^] | 142 | static const struct block_device_operations axon_ram_devops = { |
| 143 | .owner = THIS_MODULE, |
| 144 | }; |
| 145 | |
Dan Williams | 60fcd55 | 2017-01-25 15:25:11 -0800 | [diff] [blame] | 146 | static long |
| 147 | __axon_ram_direct_access(struct axon_ram_bank *bank, pgoff_t pgoff, long nr_pages, |
| 148 | void **kaddr, pfn_t *pfn) |
| 149 | { |
| 150 | resource_size_t offset = pgoff * PAGE_SIZE; |
| 151 | |
| 152 | *kaddr = (void *) bank->io_addr + offset; |
| 153 | *pfn = phys_to_pfn_t(bank->ph_addr + offset, PFN_DEV); |
| 154 | return (bank->size - offset) / PAGE_SIZE; |
| 155 | } |
| 156 | |
Dan Williams | 60fcd55 | 2017-01-25 15:25:11 -0800 | [diff] [blame] | 157 | static long |
| 158 | axon_ram_dax_direct_access(struct dax_device *dax_dev, pgoff_t pgoff, long nr_pages, |
| 159 | void **kaddr, pfn_t *pfn) |
| 160 | { |
| 161 | struct axon_ram_bank *bank = dax_get_private(dax_dev); |
| 162 | |
| 163 | return __axon_ram_direct_access(bank, pgoff, nr_pages, kaddr, pfn); |
| 164 | } |
| 165 | |
| 166 | static const struct dax_operations axon_ram_dax_ops = { |
| 167 | .direct_access = axon_ram_dax_direct_access, |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | /** |
| 171 | * axon_ram_probe - probe() method for platform driver |
Grant Likely | 0000612 | 2011-02-22 19:59:54 -0700 | [diff] [blame] | 172 | * @device: see platform_driver method |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 173 | */ |
Grant Likely | 0000612 | 2011-02-22 19:59:54 -0700 | [diff] [blame] | 174 | static int axon_ram_probe(struct platform_device *device) |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 175 | { |
| 176 | static int axon_ram_bank_id = -1; |
| 177 | struct axon_ram_bank *bank; |
| 178 | struct resource resource; |
| 179 | int rc = 0; |
| 180 | |
| 181 | axon_ram_bank_id++; |
| 182 | |
| 183 | dev_info(&device->dev, "Found memory controller on %s\n", |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 184 | device->dev.of_node->full_name); |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 185 | |
| 186 | bank = kzalloc(sizeof(struct axon_ram_bank), GFP_KERNEL); |
| 187 | if (bank == NULL) { |
| 188 | dev_err(&device->dev, "Out of memory\n"); |
| 189 | rc = -ENOMEM; |
| 190 | goto failed; |
| 191 | } |
| 192 | |
| 193 | device->dev.platform_data = bank; |
| 194 | |
| 195 | bank->device = device; |
| 196 | |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 197 | if (of_address_to_resource(device->dev.of_node, 0, &resource) != 0) { |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 198 | dev_err(&device->dev, "Cannot access device tree\n"); |
| 199 | rc = -EFAULT; |
| 200 | goto failed; |
| 201 | } |
| 202 | |
Joe Perches | 28f65c11 | 2011-06-09 09:13:32 -0700 | [diff] [blame] | 203 | bank->size = resource_size(&resource); |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 204 | |
| 205 | if (bank->size == 0) { |
| 206 | dev_err(&device->dev, "No DDR2 memory found for %s%d\n", |
| 207 | AXON_RAM_DEVICE_NAME, axon_ram_bank_id); |
| 208 | rc = -ENODEV; |
| 209 | goto failed; |
| 210 | } |
| 211 | |
| 212 | dev_info(&device->dev, "Register DDR2 memory device %s%d with %luMB\n", |
| 213 | AXON_RAM_DEVICE_NAME, axon_ram_bank_id, bank->size >> 20); |
| 214 | |
| 215 | bank->ph_addr = resource.start; |
Anton Blanchard | 40f1ce7 | 2011-05-08 21:43:47 +0000 | [diff] [blame] | 216 | bank->io_addr = (unsigned long) ioremap_prot( |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 217 | bank->ph_addr, bank->size, _PAGE_NO_CACHE); |
| 218 | if (bank->io_addr == 0) { |
| 219 | dev_err(&device->dev, "ioremap() failed\n"); |
| 220 | rc = -EFAULT; |
| 221 | goto failed; |
| 222 | } |
| 223 | |
| 224 | bank->disk = alloc_disk(AXON_RAM_MINORS_PER_DISK); |
| 225 | if (bank->disk == NULL) { |
| 226 | dev_err(&device->dev, "Cannot register disk\n"); |
| 227 | rc = -EFAULT; |
| 228 | goto failed; |
| 229 | } |
| 230 | |
Dan Williams | 60fcd55 | 2017-01-25 15:25:11 -0800 | [diff] [blame] | 231 | |
Maxim Shchetynin | 9a23409 | 2008-07-16 05:51:41 +1000 | [diff] [blame] | 232 | bank->disk->major = azfs_major; |
| 233 | bank->disk->first_minor = azfs_minor; |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 234 | bank->disk->fops = &axon_ram_devops; |
| 235 | bank->disk->private_data = bank; |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 236 | |
| 237 | sprintf(bank->disk->disk_name, "%s%d", |
| 238 | AXON_RAM_DEVICE_NAME, axon_ram_bank_id); |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 239 | |
Dan Williams | 60fcd55 | 2017-01-25 15:25:11 -0800 | [diff] [blame] | 240 | bank->dax_dev = alloc_dax(bank, bank->disk->disk_name, |
| 241 | &axon_ram_dax_ops); |
| 242 | if (!bank->dax_dev) { |
| 243 | rc = -ENOMEM; |
| 244 | goto failed; |
| 245 | } |
| 246 | |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 247 | bank->disk->queue = blk_alloc_queue(GFP_KERNEL); |
| 248 | if (bank->disk->queue == NULL) { |
| 249 | dev_err(&device->dev, "Cannot register disk queue\n"); |
| 250 | rc = -EFAULT; |
| 251 | goto failed; |
| 252 | } |
| 253 | |
| 254 | set_capacity(bank->disk, bank->size >> AXON_RAM_SECTOR_SHIFT); |
| 255 | blk_queue_make_request(bank->disk->queue, axon_ram_make_request); |
Martin K. Petersen | e1defc4 | 2009-05-22 17:17:49 -0400 | [diff] [blame] | 256 | blk_queue_logical_block_size(bank->disk->queue, AXON_RAM_SECTOR_SIZE); |
Dan Williams | 0d52c756 | 2016-06-15 19:44:20 -0700 | [diff] [blame] | 257 | device_add_disk(&device->dev, bank->disk); |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 258 | |
Grant Likely | 61c7a08 | 2010-04-13 16:12:29 -0700 | [diff] [blame] | 259 | bank->irq_id = irq_of_parse_and_map(device->dev.of_node, 0); |
Michael Ellerman | ef24ba7 | 2016-09-06 21:53:24 +1000 | [diff] [blame] | 260 | if (!bank->irq_id) { |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 261 | dev_err(&device->dev, "Cannot access ECC interrupt ID\n"); |
| 262 | rc = -EFAULT; |
| 263 | goto failed; |
| 264 | } |
| 265 | |
Maxim Shchetynin | fedcd2c | 2007-08-23 03:01:27 +1000 | [diff] [blame] | 266 | rc = request_irq(bank->irq_id, axon_ram_irq_handler, |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 267 | AXON_RAM_IRQ_FLAGS, bank->disk->disk_name, device); |
| 268 | if (rc != 0) { |
| 269 | dev_err(&device->dev, "Cannot register ECC interrupt handler\n"); |
Michael Ellerman | ef24ba7 | 2016-09-06 21:53:24 +1000 | [diff] [blame] | 270 | bank->irq_id = 0; |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 271 | rc = -EFAULT; |
| 272 | goto failed; |
| 273 | } |
| 274 | |
| 275 | rc = device_create_file(&device->dev, &dev_attr_ecc); |
| 276 | if (rc != 0) { |
| 277 | dev_err(&device->dev, "Cannot create sysfs file\n"); |
| 278 | rc = -EFAULT; |
| 279 | goto failed; |
| 280 | } |
| 281 | |
Maxim Shchetynin | 9a23409 | 2008-07-16 05:51:41 +1000 | [diff] [blame] | 282 | azfs_minor += bank->disk->minors; |
| 283 | |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 284 | return 0; |
| 285 | |
| 286 | failed: |
| 287 | if (bank != NULL) { |
Michael Ellerman | ef24ba7 | 2016-09-06 21:53:24 +1000 | [diff] [blame] | 288 | if (bank->irq_id) |
Maxim Shchetynin | fedcd2c | 2007-08-23 03:01:27 +1000 | [diff] [blame] | 289 | free_irq(bank->irq_id, device); |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 290 | if (bank->disk != NULL) { |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 291 | if (bank->disk->major > 0) |
| 292 | unregister_blkdev(bank->disk->major, |
| 293 | bank->disk->disk_name); |
Jan Kara | 672a2c8 | 2017-03-08 14:56:05 +0100 | [diff] [blame] | 294 | if (bank->disk->flags & GENHD_FL_UP) |
| 295 | del_gendisk(bank->disk); |
| 296 | put_disk(bank->disk); |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 297 | } |
Dan Williams | 60fcd55 | 2017-01-25 15:25:11 -0800 | [diff] [blame] | 298 | kill_dax(bank->dax_dev); |
| 299 | put_dax(bank->dax_dev); |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 300 | device->dev.platform_data = NULL; |
| 301 | if (bank->io_addr != 0) |
| 302 | iounmap((void __iomem *) bank->io_addr); |
| 303 | kfree(bank); |
| 304 | } |
| 305 | |
| 306 | return rc; |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * axon_ram_remove - remove() method for platform driver |
| 311 | * @device: see of_platform_driver method |
| 312 | */ |
| 313 | static int |
Grant Likely | a454dc5 | 2010-07-22 15:52:34 -0600 | [diff] [blame] | 314 | axon_ram_remove(struct platform_device *device) |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 315 | { |
| 316 | struct axon_ram_bank *bank = device->dev.platform_data; |
| 317 | |
| 318 | BUG_ON(!bank || !bank->disk); |
| 319 | |
| 320 | device_remove_file(&device->dev, &dev_attr_ecc); |
Maxim Shchetynin | fedcd2c | 2007-08-23 03:01:27 +1000 | [diff] [blame] | 321 | free_irq(bank->irq_id, device); |
Dan Williams | 60fcd55 | 2017-01-25 15:25:11 -0800 | [diff] [blame] | 322 | kill_dax(bank->dax_dev); |
| 323 | put_dax(bank->dax_dev); |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 324 | del_gendisk(bank->disk); |
Jan Kara | 672a2c8 | 2017-03-08 14:56:05 +0100 | [diff] [blame] | 325 | put_disk(bank->disk); |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 326 | iounmap((void __iomem *) bank->io_addr); |
| 327 | kfree(bank); |
| 328 | |
| 329 | return 0; |
| 330 | } |
| 331 | |
Uwe Kleine-König | ce6d73c | 2014-09-10 21:56:38 +0200 | [diff] [blame] | 332 | static const struct of_device_id axon_ram_device_id[] = { |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 333 | { |
| 334 | .type = "dma-memory" |
| 335 | }, |
| 336 | {} |
| 337 | }; |
Luis de Bethencourt | b4f8144 | 2015-10-20 16:04:13 +0100 | [diff] [blame] | 338 | MODULE_DEVICE_TABLE(of, axon_ram_device_id); |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 339 | |
Grant Likely | 0000612 | 2011-02-22 19:59:54 -0700 | [diff] [blame] | 340 | static struct platform_driver axon_ram_driver = { |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 341 | .probe = axon_ram_probe, |
Stephen Rothwell | 84dd467 | 2007-10-11 15:19:03 +1000 | [diff] [blame] | 342 | .remove = axon_ram_remove, |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 343 | .driver = { |
| 344 | .name = AXON_RAM_MODULE_NAME, |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 345 | .of_match_table = axon_ram_device_id, |
Stephen Rothwell | 84dd467 | 2007-10-11 15:19:03 +1000 | [diff] [blame] | 346 | }, |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 347 | }; |
| 348 | |
| 349 | /** |
| 350 | * axon_ram_init |
| 351 | */ |
| 352 | static int __init |
| 353 | axon_ram_init(void) |
| 354 | { |
Maxim Shchetynin | 9a23409 | 2008-07-16 05:51:41 +1000 | [diff] [blame] | 355 | azfs_major = register_blkdev(azfs_major, AXON_RAM_DEVICE_NAME); |
| 356 | if (azfs_major < 0) { |
| 357 | printk(KERN_ERR "%s cannot become block device major number\n", |
| 358 | AXON_RAM_MODULE_NAME); |
| 359 | return -EFAULT; |
| 360 | } |
| 361 | azfs_minor = 0; |
| 362 | |
Grant Likely | 0000612 | 2011-02-22 19:59:54 -0700 | [diff] [blame] | 363 | return platform_driver_register(&axon_ram_driver); |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | /** |
| 367 | * axon_ram_exit |
| 368 | */ |
| 369 | static void __exit |
| 370 | axon_ram_exit(void) |
| 371 | { |
Grant Likely | 0000612 | 2011-02-22 19:59:54 -0700 | [diff] [blame] | 372 | platform_driver_unregister(&axon_ram_driver); |
Maxim Shchetynin | 9a23409 | 2008-07-16 05:51:41 +1000 | [diff] [blame] | 373 | unregister_blkdev(azfs_major, AXON_RAM_DEVICE_NAME); |
Maxim Shchetynin | dbdf04c | 2007-07-20 21:39:26 +0200 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | module_init(axon_ram_init); |
| 377 | module_exit(axon_ram_exit); |
| 378 | |
| 379 | MODULE_LICENSE("GPL"); |
| 380 | MODULE_AUTHOR("Maxim Shchetynin <maxim@de.ibm.com>"); |
| 381 | MODULE_DESCRIPTION("Axon DDR2 RAM device driver for IBM Cell BE"); |