Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Matt Porter | 394b701 | 2005-11-07 01:00:15 -0800 | [diff] [blame] | 2 | /* |
| 3 | * RapidIO configuration space access support |
| 4 | * |
| 5 | * Copyright 2005 MontaVista Software, Inc. |
| 6 | * Matt Porter <mporter@kernel.crashing.org> |
Matt Porter | 394b701 | 2005-11-07 01:00:15 -0800 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/rio.h> |
| 10 | #include <linux/module.h> |
| 11 | |
Ben Dooks (Codethink) | bd7bca43 | 2019-12-04 16:52:34 -0800 | [diff] [blame] | 12 | #include <linux/rio_drv.h> |
| 13 | |
Matt Porter | 394b701 | 2005-11-07 01:00:15 -0800 | [diff] [blame] | 14 | /* |
Matt Porter | 394b701 | 2005-11-07 01:00:15 -0800 | [diff] [blame] | 15 | * Wrappers for all RIO configuration access functions. They just check |
Ioan Nicu | 31d1e13 | 2017-10-03 16:15:13 -0700 | [diff] [blame] | 16 | * alignment and call the low-level functions pointed to by rio_mport->ops. |
Matt Porter | 394b701 | 2005-11-07 01:00:15 -0800 | [diff] [blame] | 17 | */ |
| 18 | |
| 19 | #define RIO_8_BAD 0 |
| 20 | #define RIO_16_BAD (offset & 1) |
| 21 | #define RIO_32_BAD (offset & 3) |
| 22 | |
| 23 | /** |
| 24 | * RIO_LOP_READ - Generate rio_local_read_config_* functions |
| 25 | * @size: Size of configuration space read (8, 16, 32 bits) |
| 26 | * @type: C type of value argument |
| 27 | * @len: Length of configuration space read (1, 2, 4 bytes) |
| 28 | * |
| 29 | * Generates rio_local_read_config_* functions used to access |
| 30 | * configuration space registers on the local device. |
| 31 | */ |
| 32 | #define RIO_LOP_READ(size,type,len) \ |
| 33 | int __rio_local_read_config_##size \ |
| 34 | (struct rio_mport *mport, u32 offset, type *value) \ |
| 35 | { \ |
| 36 | int res; \ |
Matt Porter | 394b701 | 2005-11-07 01:00:15 -0800 | [diff] [blame] | 37 | u32 data = 0; \ |
| 38 | if (RIO_##size##_BAD) return RIO_BAD_SIZE; \ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 39 | res = mport->ops->lcread(mport, mport->id, offset, len, &data); \ |
Matt Porter | 394b701 | 2005-11-07 01:00:15 -0800 | [diff] [blame] | 40 | *value = (type)data; \ |
Matt Porter | 394b701 | 2005-11-07 01:00:15 -0800 | [diff] [blame] | 41 | return res; \ |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * RIO_LOP_WRITE - Generate rio_local_write_config_* functions |
| 46 | * @size: Size of configuration space write (8, 16, 32 bits) |
| 47 | * @type: C type of value argument |
| 48 | * @len: Length of configuration space write (1, 2, 4 bytes) |
| 49 | * |
| 50 | * Generates rio_local_write_config_* functions used to access |
| 51 | * configuration space registers on the local device. |
| 52 | */ |
| 53 | #define RIO_LOP_WRITE(size,type,len) \ |
| 54 | int __rio_local_write_config_##size \ |
| 55 | (struct rio_mport *mport, u32 offset, type value) \ |
| 56 | { \ |
Matt Porter | 394b701 | 2005-11-07 01:00:15 -0800 | [diff] [blame] | 57 | if (RIO_##size##_BAD) return RIO_BAD_SIZE; \ |
Ioan Nicu | 31d1e13 | 2017-10-03 16:15:13 -0700 | [diff] [blame] | 58 | return mport->ops->lcwrite(mport, mport->id, offset, len, value);\ |
Matt Porter | 394b701 | 2005-11-07 01:00:15 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | RIO_LOP_READ(8, u8, 1) |
| 62 | RIO_LOP_READ(16, u16, 2) |
| 63 | RIO_LOP_READ(32, u32, 4) |
| 64 | RIO_LOP_WRITE(8, u8, 1) |
| 65 | RIO_LOP_WRITE(16, u16, 2) |
| 66 | RIO_LOP_WRITE(32, u32, 4) |
| 67 | |
| 68 | EXPORT_SYMBOL_GPL(__rio_local_read_config_8); |
| 69 | EXPORT_SYMBOL_GPL(__rio_local_read_config_16); |
| 70 | EXPORT_SYMBOL_GPL(__rio_local_read_config_32); |
| 71 | EXPORT_SYMBOL_GPL(__rio_local_write_config_8); |
| 72 | EXPORT_SYMBOL_GPL(__rio_local_write_config_16); |
| 73 | EXPORT_SYMBOL_GPL(__rio_local_write_config_32); |
| 74 | |
| 75 | /** |
| 76 | * RIO_OP_READ - Generate rio_mport_read_config_* functions |
| 77 | * @size: Size of configuration space read (8, 16, 32 bits) |
| 78 | * @type: C type of value argument |
| 79 | * @len: Length of configuration space read (1, 2, 4 bytes) |
| 80 | * |
| 81 | * Generates rio_mport_read_config_* functions used to access |
| 82 | * configuration space registers on the local device. |
| 83 | */ |
| 84 | #define RIO_OP_READ(size,type,len) \ |
| 85 | int rio_mport_read_config_##size \ |
| 86 | (struct rio_mport *mport, u16 destid, u8 hopcount, u32 offset, type *value) \ |
| 87 | { \ |
| 88 | int res; \ |
Matt Porter | 394b701 | 2005-11-07 01:00:15 -0800 | [diff] [blame] | 89 | u32 data = 0; \ |
| 90 | if (RIO_##size##_BAD) return RIO_BAD_SIZE; \ |
Zhang Wei | ad1e938 | 2008-04-18 13:33:41 -0700 | [diff] [blame] | 91 | res = mport->ops->cread(mport, mport->id, destid, hopcount, offset, len, &data); \ |
Matt Porter | 394b701 | 2005-11-07 01:00:15 -0800 | [diff] [blame] | 92 | *value = (type)data; \ |
Matt Porter | 394b701 | 2005-11-07 01:00:15 -0800 | [diff] [blame] | 93 | return res; \ |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * RIO_OP_WRITE - Generate rio_mport_write_config_* functions |
| 98 | * @size: Size of configuration space write (8, 16, 32 bits) |
| 99 | * @type: C type of value argument |
| 100 | * @len: Length of configuration space write (1, 2, 4 bytes) |
| 101 | * |
| 102 | * Generates rio_mport_write_config_* functions used to access |
| 103 | * configuration space registers on the local device. |
| 104 | */ |
| 105 | #define RIO_OP_WRITE(size,type,len) \ |
| 106 | int rio_mport_write_config_##size \ |
| 107 | (struct rio_mport *mport, u16 destid, u8 hopcount, u32 offset, type value) \ |
| 108 | { \ |
Matt Porter | 394b701 | 2005-11-07 01:00:15 -0800 | [diff] [blame] | 109 | if (RIO_##size##_BAD) return RIO_BAD_SIZE; \ |
Ioan Nicu | 31d1e13 | 2017-10-03 16:15:13 -0700 | [diff] [blame] | 110 | return mport->ops->cwrite(mport, mport->id, destid, hopcount, \ |
| 111 | offset, len, value); \ |
Matt Porter | 394b701 | 2005-11-07 01:00:15 -0800 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | RIO_OP_READ(8, u8, 1) |
| 115 | RIO_OP_READ(16, u16, 2) |
| 116 | RIO_OP_READ(32, u32, 4) |
| 117 | RIO_OP_WRITE(8, u8, 1) |
| 118 | RIO_OP_WRITE(16, u16, 2) |
| 119 | RIO_OP_WRITE(32, u32, 4) |
| 120 | |
| 121 | EXPORT_SYMBOL_GPL(rio_mport_read_config_8); |
| 122 | EXPORT_SYMBOL_GPL(rio_mport_read_config_16); |
| 123 | EXPORT_SYMBOL_GPL(rio_mport_read_config_32); |
| 124 | EXPORT_SYMBOL_GPL(rio_mport_write_config_8); |
| 125 | EXPORT_SYMBOL_GPL(rio_mport_write_config_16); |
| 126 | EXPORT_SYMBOL_GPL(rio_mport_write_config_32); |
| 127 | |
| 128 | /** |
| 129 | * rio_mport_send_doorbell - Send a doorbell message |
| 130 | * |
| 131 | * @mport: RIO master port |
| 132 | * @destid: RIO device destination ID |
| 133 | * @data: Doorbell message data |
| 134 | * |
| 135 | * Send a doorbell message to a RIO device. The doorbell message |
| 136 | * has a 16-bit info field provided by the data argument. |
| 137 | */ |
| 138 | int rio_mport_send_doorbell(struct rio_mport *mport, u16 destid, u16 data) |
| 139 | { |
Ioan Nicu | 31d1e13 | 2017-10-03 16:15:13 -0700 | [diff] [blame] | 140 | return mport->ops->dsend(mport, mport->id, destid, data); |
Matt Porter | 394b701 | 2005-11-07 01:00:15 -0800 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | EXPORT_SYMBOL_GPL(rio_mport_send_doorbell); |