0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/kernel.h>
0010 #include <linux/list.h>
0011 #include <linux/module.h>
0012 #include <linux/slab.h>
0013 #include <linux/string.h>
0014
0015 #include <asm/hvcall.h>
0016 #include <asm/hvcserver.h>
0017 #include <asm/io.h>
0018
0019 #define HVCS_ARCH_VERSION "1.0.0"
0020
0021 MODULE_AUTHOR("Ryan S. Arnold <rsa@us.ibm.com>");
0022 MODULE_DESCRIPTION("IBM hvcs ppc64 API");
0023 MODULE_LICENSE("GPL");
0024 MODULE_VERSION(HVCS_ARCH_VERSION);
0025
0026
0027
0028
0029
0030
0031 static int hvcs_convert(long to_convert)
0032 {
0033 switch (to_convert) {
0034 case H_SUCCESS:
0035 return 0;
0036 case H_PARAMETER:
0037 return -EINVAL;
0038 case H_HARDWARE:
0039 return -EIO;
0040 case H_BUSY:
0041 case H_LONG_BUSY_ORDER_1_MSEC:
0042 case H_LONG_BUSY_ORDER_10_MSEC:
0043 case H_LONG_BUSY_ORDER_100_MSEC:
0044 case H_LONG_BUSY_ORDER_1_SEC:
0045 case H_LONG_BUSY_ORDER_10_SEC:
0046 case H_LONG_BUSY_ORDER_100_SEC:
0047 return -EBUSY;
0048 case H_FUNCTION:
0049 default:
0050 return -EPERM;
0051 }
0052 }
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062 int hvcs_free_partner_info(struct list_head *head)
0063 {
0064 struct hvcs_partner_info *pi;
0065 struct list_head *element;
0066
0067 if (!head)
0068 return -EINVAL;
0069
0070 while (!list_empty(head)) {
0071 element = head->next;
0072 pi = list_entry(element, struct hvcs_partner_info, node);
0073 list_del(element);
0074 kfree(pi);
0075 }
0076
0077 return 0;
0078 }
0079 EXPORT_SYMBOL(hvcs_free_partner_info);
0080
0081
0082 static int hvcs_next_partner(uint32_t unit_address,
0083 unsigned long last_p_partition_ID,
0084 unsigned long last_p_unit_address, unsigned long *pi_buff)
0085
0086 {
0087 long retval;
0088 retval = plpar_hcall_norets(H_VTERM_PARTNER_INFO, unit_address,
0089 last_p_partition_ID,
0090 last_p_unit_address, virt_to_phys(pi_buff));
0091 return hvcs_convert(retval);
0092 }
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119 int hvcs_get_partner_info(uint32_t unit_address, struct list_head *head,
0120 unsigned long *pi_buff)
0121 {
0122
0123
0124
0125
0126 unsigned long last_p_partition_ID;
0127 unsigned long last_p_unit_address;
0128 struct hvcs_partner_info *next_partner_info = NULL;
0129 int more = 1;
0130 int retval;
0131
0132
0133 if (!head || !pi_buff)
0134 return -EINVAL;
0135
0136 memset(pi_buff, 0x00, PAGE_SIZE);
0137 last_p_partition_ID = last_p_unit_address = ~0UL;
0138 INIT_LIST_HEAD(head);
0139
0140 do {
0141 retval = hvcs_next_partner(unit_address, last_p_partition_ID,
0142 last_p_unit_address, pi_buff);
0143 if (retval) {
0144
0145
0146
0147
0148 if (!list_empty(head))
0149 return 0;
0150 return retval;
0151 }
0152
0153 last_p_partition_ID = be64_to_cpu(pi_buff[0]);
0154 last_p_unit_address = be64_to_cpu(pi_buff[1]);
0155
0156
0157 if (last_p_partition_ID == ~0UL
0158 && last_p_unit_address == ~0UL)
0159 break;
0160
0161
0162
0163 next_partner_info = kmalloc(sizeof(struct hvcs_partner_info),
0164 GFP_ATOMIC);
0165
0166 if (!next_partner_info) {
0167 printk(KERN_WARNING "HVCONSOLE: kmalloc() failed to"
0168 " allocate partner info struct.\n");
0169 hvcs_free_partner_info(head);
0170 return -ENOMEM;
0171 }
0172
0173 next_partner_info->unit_address
0174 = (unsigned int)last_p_unit_address;
0175 next_partner_info->partition_ID
0176 = (unsigned int)last_p_partition_ID;
0177
0178
0179 strlcpy(&next_partner_info->location_code[0],
0180 (char *)&pi_buff[2],
0181 sizeof(next_partner_info->location_code));
0182
0183 list_add_tail(&(next_partner_info->node), head);
0184 next_partner_info = NULL;
0185
0186 } while (more);
0187
0188 return 0;
0189 }
0190 EXPORT_SYMBOL(hvcs_get_partner_info);
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213 int hvcs_register_connection( uint32_t unit_address,
0214 uint32_t p_partition_ID, uint32_t p_unit_address)
0215 {
0216 long retval;
0217 retval = plpar_hcall_norets(H_REGISTER_VTERM, unit_address,
0218 p_partition_ID, p_unit_address);
0219 return hvcs_convert(retval);
0220 }
0221 EXPORT_SYMBOL(hvcs_register_connection);
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233 int hvcs_free_connection(uint32_t unit_address)
0234 {
0235 long retval;
0236 retval = plpar_hcall_norets(H_FREE_VTERM, unit_address);
0237 return hvcs_convert(retval);
0238 }
0239 EXPORT_SYMBOL(hvcs_free_connection);