Merge branch 'x86-asm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[cascardo/linux.git] / drivers / staging / unisys / visorutil / visorkmodutils.c
1 /* timskmodutils.c
2  *
3  * Copyright (C) 2010 - 2013 UNISYS CORPORATION
4  * All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or (at
9  * your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
14  * NON INFRINGEMENT.  See the GNU General Public License for more
15  * details.
16  */
17
18 #include "uniklog.h"
19 #include "timskmod.h"
20
21 #define MYDRVNAME "timskmodutils"
22
23 /* s-Par uses the Intel processor's VT-X features to separate groups of
24  * processors into partitions. The firmware sets the hypervisor bit and
25  * reports an ID in the HV capabilities leaf so that the partition's OS
26  * knows s-Par is present and managing the processors.
27  */
28
29 #define UNISYS_SPAR_LEAF_ID 0x40000000
30
31 /* The s-Par leaf ID returns "UnisysSpar64" encoded across ebx, ecx, edx */
32 #define UNISYS_SPAR_ID_EBX 0x73696e55
33 #define UNISYS_SPAR_ID_ECX 0x70537379
34 #define UNISYS_SPAR_ID_EDX 0x34367261
35
36 int unisys_spar_platform;
37 EXPORT_SYMBOL_GPL(unisys_spar_platform);
38
39 /** Callers to interfaces that set __GFP_NORETRY flag below
40  *  must check for a NULL (error) result as we are telling the
41  *  kernel interface that it is okay to fail.
42  */
43
44 void *kmalloc_kernel(size_t siz)
45 {
46         return kmalloc(siz, GFP_KERNEL | __GFP_NORETRY);
47 }
48
49 static __init uint32_t
50 visorutil_spar_detect(void)
51 {
52         unsigned int eax, ebx, ecx, edx;
53
54         if (cpu_has_hypervisor) {
55                 /* check the ID */
56                 cpuid(UNISYS_SPAR_LEAF_ID, &eax, &ebx, &ecx, &edx);
57                 return  (ebx == UNISYS_SPAR_ID_EBX) &&
58                         (ecx == UNISYS_SPAR_ID_ECX) &&
59                         (edx == UNISYS_SPAR_ID_EDX);
60         } else
61                 return 0;
62
63 }
64
65
66
67
68 static __init int
69 visorutil_mod_init(void)
70 {
71         if (visorutil_spar_detect()) {
72                 unisys_spar_platform = TRUE;
73                 return 0;
74         } else
75                 return -ENODEV;
76 }
77
78 static __exit void
79 visorutil_mod_exit(void)
80 {
81 }
82
83 module_init(visorutil_mod_init);
84 module_exit(visorutil_mod_exit);
85
86 MODULE_LICENSE("GPL");