Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
hvcserver.c
Go to the documentation of this file.
1 /*
2  * hvcserver.c
3  * Copyright (C) 2004 Ryan S Arnold, IBM Corporation
4  *
5  * PPC64 virtual I/O console server support.
6  *
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.
11  *
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.
16  *
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
20  */
21 
22 #include <linux/kernel.h>
23 #include <linux/list.h>
24 #include <linux/module.h>
25 #include <linux/slab.h>
26 
27 #include <asm/hvcall.h>
28 #include <asm/hvcserver.h>
29 #include <asm/io.h>
30 
31 #define HVCS_ARCH_VERSION "1.0.0"
32 
33 MODULE_AUTHOR("Ryan S. Arnold <[email protected]>");
34 MODULE_DESCRIPTION("IBM hvcs ppc64 API");
35 MODULE_LICENSE("GPL");
37 
38 /*
39  * Convert arch specific return codes into relevant errnos. The hvcs
40  * functions aren't performance sensitive, so this conversion isn't an
41  * issue.
42  */
43 static int hvcs_convert(long to_convert)
44 {
45  switch (to_convert) {
46  case H_SUCCESS:
47  return 0;
48  case H_PARAMETER:
49  return -EINVAL;
50  case H_HARDWARE:
51  return -EIO;
52  case H_BUSY:
53  case H_LONG_BUSY_ORDER_1_MSEC:
54  case H_LONG_BUSY_ORDER_10_MSEC:
55  case H_LONG_BUSY_ORDER_100_MSEC:
56  case H_LONG_BUSY_ORDER_1_SEC:
57  case H_LONG_BUSY_ORDER_10_SEC:
58  case H_LONG_BUSY_ORDER_100_SEC:
59  return -EBUSY;
60  case H_FUNCTION: /* fall through */
61  default:
62  return -EPERM;
63  }
64 }
65 
75 {
76  struct hvcs_partner_info *pi;
77  struct list_head *element;
78 
79  if (!head)
80  return -EINVAL;
81 
82  while (!list_empty(head)) {
83  element = head->next;
84  pi = list_entry(element, struct hvcs_partner_info, node);
85  list_del(element);
86  kfree(pi);
87  }
88 
89  return 0;
90 }
92 
93 /* Helper function for hvcs_get_partner_info */
94 static int hvcs_next_partner(uint32_t unit_address,
95  unsigned long last_p_partition_ID,
96  unsigned long last_p_unit_address, unsigned long *pi_buff)
97 
98 {
99  long retval;
100  retval = plpar_hcall_norets(H_VTERM_PARTNER_INFO, unit_address,
101  last_p_partition_ID,
102  last_p_unit_address, virt_to_phys(pi_buff));
103  return hvcs_convert(retval);
104 }
105 
131 int hvcs_get_partner_info(uint32_t unit_address, struct list_head *head,
132  unsigned long *pi_buff)
133 {
134  /*
135  * Dealt with as longs because of the hcall interface even though the
136  * values are uint32_t.
137  */
138  unsigned long last_p_partition_ID;
139  unsigned long last_p_unit_address;
140  struct hvcs_partner_info *next_partner_info = NULL;
141  int more = 1;
142  int retval;
143 
144  memset(pi_buff, 0x00, PAGE_SIZE);
145  /* invalid parameters */
146  if (!head || !pi_buff)
147  return -EINVAL;
148 
149  last_p_partition_ID = last_p_unit_address = ~0UL;
150  INIT_LIST_HEAD(head);
151 
152  do {
153  retval = hvcs_next_partner(unit_address, last_p_partition_ID,
154  last_p_unit_address, pi_buff);
155  if (retval) {
156  /*
157  * Don't indicate that we've failed if we have
158  * any list elements.
159  */
160  if (!list_empty(head))
161  return 0;
162  return retval;
163  }
164 
165  last_p_partition_ID = pi_buff[0];
166  last_p_unit_address = pi_buff[1];
167 
168  /* This indicates that there are no further partners */
169  if (last_p_partition_ID == ~0UL
170  && last_p_unit_address == ~0UL)
171  break;
172 
173  /* This is a very small struct and will be freed soon in
174  * hvcs_free_partner_info(). */
175  next_partner_info = kmalloc(sizeof(struct hvcs_partner_info),
176  GFP_ATOMIC);
177 
178  if (!next_partner_info) {
179  printk(KERN_WARNING "HVCONSOLE: kmalloc() failed to"
180  " allocate partner info struct.\n");
182  return -ENOMEM;
183  }
184 
185  next_partner_info->unit_address
186  = (unsigned int)last_p_unit_address;
187  next_partner_info->partition_ID
188  = (unsigned int)last_p_partition_ID;
189 
190  /* copy the Null-term char too */
191  strncpy(&next_partner_info->location_code[0],
192  (char *)&pi_buff[2],
193  strlen((char *)&pi_buff[2]) + 1);
194 
195  list_add_tail(&(next_partner_info->node), head);
196  next_partner_info = NULL;
197 
198  } while (more);
199 
200  return 0;
201 }
203 
226  uint32_t p_partition_ID, uint32_t p_unit_address)
227 {
228  long retval;
229  retval = plpar_hcall_norets(H_REGISTER_VTERM, unit_address,
230  p_partition_ID, p_unit_address);
231  return hvcs_convert(retval);
232 }
234 
246 {
247  long retval;
248  retval = plpar_hcall_norets(H_FREE_VTERM, unit_address);
249  return hvcs_convert(retval);
250 }