3 * Copyright (C) 2004 Ryan S Arnold, IBM Corporation
5 * PPC64 virtual I/O console server support.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <linux/kernel.h>
23 #include <linux/list.h>
24 #include <linux/module.h>
25 #include <asm/hvcall.h>
26 #include <asm/hvcserver.h>
29 #define HVCS_ARCH_VERSION "1.0.0"
31 MODULE_AUTHOR("Ryan S. Arnold <rsa@us.ibm.com>");
32 MODULE_DESCRIPTION("IBM hvcs ppc64 API");
33 MODULE_LICENSE("GPL");
34 MODULE_VERSION(HVCS_ARCH_VERSION);
37 * Convert arch specific return codes into relevant errnos. The hvcs
38 * functions aren't performance sensitive, so this conversion isn't an
41 int hvcs_convert(long to_convert)
51 case H_LongBusyOrder1msec:
52 case H_LongBusyOrder10msec:
53 case H_LongBusyOrder100msec:
54 case H_LongBusyOrder1sec:
55 case H_LongBusyOrder10sec:
56 case H_LongBusyOrder100sec:
58 case H_Function: /* fall through */
64 int hvcs_free_partner_info(struct list_head *head)
66 struct hvcs_partner_info *pi;
67 struct list_head *element;
73 while (!list_empty(head)) {
75 pi = list_entry(element, struct hvcs_partner_info, node);
82 EXPORT_SYMBOL(hvcs_free_partner_info);
84 /* Helper function for hvcs_get_partner_info */
85 int hvcs_next_partner(unsigned int unit_address,
86 unsigned long last_p_partition_ID,
87 unsigned long last_p_unit_address, unsigned long *pi_buff)
91 retval = plpar_hcall_norets(H_VTERM_PARTNER_INFO, unit_address,
93 last_p_unit_address, virt_to_phys(pi_buff));
94 return hvcs_convert(retval);
98 * The unit_address parameter is the unit address of the vty-server vdevice
99 * in whose partner information the caller is interested. This function
100 * uses a pointer to a list_head instance in which to store the partner info.
101 * This function returns non-zero on success, or if there is no partner info.
103 * Invocation of this function should always be followed by an invocation of
104 * hvcs_free_partner_info() using a pointer to the SAME list head instance
105 * that was used to store the partner_info list.
107 int hvcs_get_partner_info(unsigned int unit_address, struct list_head *head,
108 unsigned long *pi_buff)
111 * This is a page sized buffer to be passed to hvcall per invocation.
112 * NOTE: the first long returned is unit_address. The second long
113 * returned is the partition ID and starting with pi_buff[2] are
114 * HVCS_CLC_LENGTH characters, which are diff size than the unsigned
115 * long, hence the casting mumbojumbo you see later.
117 unsigned long last_p_partition_ID;
118 unsigned long last_p_unit_address;
119 struct hvcs_partner_info *next_partner_info = NULL;
123 memset(pi_buff, 0x00, PAGE_SIZE);
124 /* invalid parameters */
128 last_p_partition_ID = last_p_unit_address = ~0UL;
129 INIT_LIST_HEAD(head);
135 retval = hvcs_next_partner(unit_address, last_p_partition_ID,
136 last_p_unit_address, pi_buff);
139 * Don't indicate that we've failed if we have
142 if (!list_empty(head))
147 last_p_partition_ID = pi_buff[0];
148 last_p_unit_address = pi_buff[1];
150 /* This indicates that there are no further partners */
151 if (last_p_partition_ID == ~0UL
152 && last_p_unit_address == ~0UL)
155 /* This is a very small struct and will be freed soon in
156 * hvcs_free_partner_info(). */
157 next_partner_info = kmalloc(sizeof(struct hvcs_partner_info),
160 if (!next_partner_info) {
161 printk(KERN_WARNING "HVCONSOLE: kmalloc() failed to"
162 " allocate partner info struct.\n");
163 hvcs_free_partner_info(head);
167 next_partner_info->unit_address
168 = (unsigned int)last_p_unit_address;
169 next_partner_info->partition_ID
170 = (unsigned int)last_p_partition_ID;
172 /* copy the Null-term char too */
173 strncpy(&next_partner_info->location_code[0],
175 strlen((char *)&pi_buff[2]) + 1);
177 list_add_tail(&(next_partner_info->node), head);
178 next_partner_info = NULL;
184 EXPORT_SYMBOL(hvcs_get_partner_info);
187 * If this function is called once and -EINVAL is returned it may
188 * indicate that the partner info needs to be refreshed for the
189 * target unit address at which point the caller must invoke
190 * hvcs_get_partner_info() and then call this function again. If,
191 * for a second time, -EINVAL is returned then it indicates that
192 * there is probably already a partner connection registered to a
193 * different vty-server@ vdevice. It is also possible that a second
194 * -EINVAL may indicate that one of the parms is not valid, for
195 * instance if the link was removed between the vty-server@ vdevice
196 * and the vty@ vdevice that you are trying to open. Don't shoot the
197 * messenger. Firmware implemented it this way.
199 int hvcs_register_connection( unsigned int unit_address,
200 unsigned int p_partition_ID, unsigned int p_unit_address)
203 retval = plpar_hcall_norets(H_REGISTER_VTERM, unit_address,
204 p_partition_ID, p_unit_address);
205 return hvcs_convert(retval);
207 EXPORT_SYMBOL(hvcs_register_connection);
210 * If -EBUSY is returned continue to call this function
211 * until 0 is returned.
213 int hvcs_free_connection(unsigned int unit_address)
216 retval = plpar_hcall_norets(H_FREE_VTERM, unit_address);
217 return hvcs_convert(retval);
219 EXPORT_SYMBOL(hvcs_free_connection);