Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of version 2 of the GNU General Public License as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 11 | * General Public License for more details. |
| 12 | */ |
| 13 | #ifndef __LINUX_ND_H__ |
| 14 | #define __LINUX_ND_H__ |
| 15 | #include <linux/ndctl.h> |
| 16 | #include <linux/device.h> |
| 17 | |
| 18 | struct nd_device_driver { |
| 19 | struct device_driver drv; |
| 20 | unsigned long type; |
| 21 | int (*probe)(struct device *dev); |
| 22 | int (*remove)(struct device *dev); |
| 23 | }; |
| 24 | |
| 25 | static inline struct nd_device_driver *to_nd_device_driver( |
| 26 | struct device_driver *drv) |
| 27 | { |
| 28 | return container_of(drv, struct nd_device_driver, drv); |
Dan Williams | 3d88002 | 2015-05-31 15:02:11 -0400 | [diff] [blame] | 29 | }; |
| 30 | |
Dan Williams | bf9bccc | 2015-06-17 17:14:46 -0400 | [diff] [blame] | 31 | /** |
| 32 | * struct nd_namespace_io - infrastructure for loading an nd_pmem instance |
| 33 | * @dev: namespace device created by the nd region driver |
| 34 | * @res: struct resource conversion of a NFIT SPA table |
| 35 | */ |
Dan Williams | 3d88002 | 2015-05-31 15:02:11 -0400 | [diff] [blame] | 36 | struct nd_namespace_io { |
| 37 | struct device dev; |
| 38 | struct resource res; |
| 39 | }; |
| 40 | |
Dan Williams | bf9bccc | 2015-06-17 17:14:46 -0400 | [diff] [blame] | 41 | /** |
| 42 | * struct nd_namespace_pmem - namespace device for dimm-backed interleaved memory |
| 43 | * @nsio: device and system physical address range to drive |
| 44 | * @alt_name: namespace name supplied in the dimm label |
| 45 | * @uuid: namespace name supplied in the dimm label |
| 46 | */ |
| 47 | struct nd_namespace_pmem { |
| 48 | struct nd_namespace_io nsio; |
| 49 | char *alt_name; |
| 50 | u8 *uuid; |
| 51 | }; |
| 52 | |
Dan Williams | 1b40e09 | 2015-05-01 13:34:01 -0400 | [diff] [blame^] | 53 | /** |
| 54 | * struct nd_namespace_blk - namespace for dimm-bounded persistent memory |
| 55 | * @dev: namespace device creation by the nd region driver |
| 56 | * @alt_name: namespace name supplied in the dimm label |
| 57 | * @uuid: namespace name supplied in the dimm label |
| 58 | * @id: ida allocated id |
| 59 | * @lbasize: blk namespaces have a native sector size when btt not present |
| 60 | * @num_resources: number of dpa extents to claim |
| 61 | * @res: discontiguous dpa extents for given dimm |
| 62 | */ |
| 63 | struct nd_namespace_blk { |
| 64 | struct device dev; |
| 65 | char *alt_name; |
| 66 | u8 *uuid; |
| 67 | int id; |
| 68 | unsigned long lbasize; |
| 69 | int num_resources; |
| 70 | struct resource **res; |
| 71 | }; |
| 72 | |
Dan Williams | 3d88002 | 2015-05-31 15:02:11 -0400 | [diff] [blame] | 73 | static inline struct nd_namespace_io *to_nd_namespace_io(struct device *dev) |
| 74 | { |
| 75 | return container_of(dev, struct nd_namespace_io, dev); |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 76 | } |
| 77 | |
Dan Williams | bf9bccc | 2015-06-17 17:14:46 -0400 | [diff] [blame] | 78 | static inline struct nd_namespace_pmem *to_nd_namespace_pmem(struct device *dev) |
| 79 | { |
| 80 | struct nd_namespace_io *nsio = to_nd_namespace_io(dev); |
| 81 | |
| 82 | return container_of(nsio, struct nd_namespace_pmem, nsio); |
| 83 | } |
| 84 | |
Dan Williams | 1b40e09 | 2015-05-01 13:34:01 -0400 | [diff] [blame^] | 85 | static inline struct nd_namespace_blk *to_nd_namespace_blk(struct device *dev) |
| 86 | { |
| 87 | return container_of(dev, struct nd_namespace_blk, dev); |
| 88 | } |
| 89 | |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 90 | #define MODULE_ALIAS_ND_DEVICE(type) \ |
| 91 | MODULE_ALIAS("nd:t" __stringify(type) "*") |
| 92 | #define ND_DEVICE_MODALIAS_FMT "nd:t%d" |
| 93 | |
| 94 | int __must_check __nd_driver_register(struct nd_device_driver *nd_drv, |
| 95 | struct module *module, const char *mod_name); |
| 96 | #define nd_driver_register(driver) \ |
| 97 | __nd_driver_register(driver, THIS_MODULE, KBUILD_MODNAME) |
| 98 | #endif /* __LINUX_ND_H__ */ |