2 * drivers/s390/char/sclp_cpi_sys.c
3 * SCLP control program identification sysfs interface
5 * Copyright IBM Corp. 2001, 2007
6 * Author(s): Martin Peschke <mpeschke@de.ibm.com>
7 * Michael Ernst <mernst@de.ibm.com>
10 #include <linux/kernel.h>
11 #include <linux/init.h>
12 #include <linux/stat.h>
13 #include <linux/device.h>
14 #include <linux/string.h>
15 #include <linux/ctype.h>
16 #include <linux/kmod.h>
17 #include <linux/timer.h>
18 #include <linux/err.h>
19 #include <linux/slab.h>
20 #include <linux/completion.h>
21 #include <asm/ebcdic.h>
25 #include "sclp_cpi_sys.h"
27 #define CPI_LENGTH_NAME 8
28 #define CPI_LENGTH_LEVEL 16
31 struct evbuf_header header
;
34 u8 system_type
[CPI_LENGTH_NAME
];
36 u8 system_name
[CPI_LENGTH_NAME
];
40 u8 sysplex_name
[CPI_LENGTH_NAME
];
42 } __attribute__((packed
));
45 struct sccb_header header
;
46 struct cpi_evbuf cpi_evbuf
;
47 } __attribute__((packed
));
49 static struct sclp_register sclp_cpi_event
= {
50 .send_mask
= EVTYP_CTLPROGIDENT_MASK
,
53 static char system_name
[CPI_LENGTH_NAME
+ 1];
54 static char sysplex_name
[CPI_LENGTH_NAME
+ 1];
55 static char system_type
[CPI_LENGTH_NAME
+ 1];
56 static u64 system_level
;
58 static void set_data(char *field
, char *data
)
60 memset(field
, ' ', CPI_LENGTH_NAME
);
61 memcpy(field
, data
, strlen(data
));
62 sclp_ascebc_str(field
, CPI_LENGTH_NAME
);
65 static void cpi_callback(struct sclp_req
*req
, void *data
)
67 struct completion
*completion
= data
;
72 static struct sclp_req
*cpi_prepare_req(void)
75 struct cpi_sccb
*sccb
;
76 struct cpi_evbuf
*evb
;
78 req
= kzalloc(sizeof(struct sclp_req
), GFP_KERNEL
);
80 return ERR_PTR(-ENOMEM
);
81 sccb
= (struct cpi_sccb
*) get_zeroed_page(GFP_KERNEL
| GFP_DMA
);
84 return ERR_PTR(-ENOMEM
);
87 /* setup SCCB for Control-Program Identification */
88 sccb
->header
.length
= sizeof(struct cpi_sccb
);
89 sccb
->cpi_evbuf
.header
.length
= sizeof(struct cpi_evbuf
);
90 sccb
->cpi_evbuf
.header
.type
= 0x0b;
91 evb
= &sccb
->cpi_evbuf
;
94 set_data(evb
->system_type
, system_type
);
97 set_data(evb
->system_name
, system_name
);
100 evb
->system_level
= system_level
;
102 /* set sysplex name */
103 set_data(evb
->sysplex_name
, sysplex_name
);
105 /* prepare request data structure presented to SCLP driver */
106 req
->command
= SCLP_CMDW_WRITE_EVENT_DATA
;
108 req
->status
= SCLP_REQ_FILLED
;
109 req
->callback
= cpi_callback
;
113 static void cpi_free_req(struct sclp_req
*req
)
115 free_page((unsigned long) req
->sccb
);
119 static int cpi_req(void)
121 struct completion completion
;
122 struct sclp_req
*req
;
126 rc
= sclp_register(&sclp_cpi_event
);
128 printk(KERN_WARNING
"cpi: could not register "
129 "to hardware console.\n");
132 if (!(sclp_cpi_event
.sclp_send_mask
& EVTYP_CTLPROGIDENT_MASK
)) {
133 printk(KERN_WARNING
"cpi: no control program "
134 "identification support\n");
139 req
= cpi_prepare_req();
141 printk(KERN_WARNING
"cpi: could not allocate request\n");
146 init_completion(&completion
);
147 req
->callback_data
= &completion
;
149 /* Add request to sclp queue */
150 rc
= sclp_add_request(req
);
152 printk(KERN_WARNING
"cpi: could not start request\n");
156 wait_for_completion(&completion
);
158 if (req
->status
!= SCLP_REQ_DONE
) {
159 printk(KERN_WARNING
"cpi: request failed (status=0x%02x)\n",
165 response
= ((struct cpi_sccb
*) req
->sccb
)->header
.response_code
;
166 if (response
!= 0x0020) {
167 printk(KERN_WARNING
"cpi: failed with "
168 "response code 0x%x\n", response
);
176 sclp_unregister(&sclp_cpi_event
);
182 static int check_string(const char *attr
, const char *str
)
189 if ((len
> 0) && (str
[len
- 1] == '\n'))
192 if (len
> CPI_LENGTH_NAME
)
195 for (i
= 0; i
< len
; i
++) {
196 if (isalpha(str
[i
]) || isdigit(str
[i
]) ||
197 strchr("$@# ", str
[i
]))
205 static void set_string(char *attr
, const char *value
)
212 if ((len
> 0) && (value
[len
- 1] == '\n'))
215 for (i
= 0; i
< CPI_LENGTH_NAME
; i
++) {
217 attr
[i
] = toupper(value
[i
]);
223 static ssize_t
system_name_show(struct kobject
*kobj
,
224 struct kobj_attribute
*attr
, char *page
)
226 return snprintf(page
, PAGE_SIZE
, "%s\n", system_name
);
229 static ssize_t
system_name_store(struct kobject
*kobj
,
230 struct kobj_attribute
*attr
,
236 rc
= check_string("system_name", buf
);
240 set_string(system_name
, buf
);
245 static struct kobj_attribute system_name_attr
=
246 __ATTR(system_name
, 0644, system_name_show
, system_name_store
);
248 static ssize_t
sysplex_name_show(struct kobject
*kobj
,
249 struct kobj_attribute
*attr
, char *page
)
251 return snprintf(page
, PAGE_SIZE
, "%s\n", sysplex_name
);
254 static ssize_t
sysplex_name_store(struct kobject
*kobj
,
255 struct kobj_attribute
*attr
,
261 rc
= check_string("sysplex_name", buf
);
265 set_string(sysplex_name
, buf
);
270 static struct kobj_attribute sysplex_name_attr
=
271 __ATTR(sysplex_name
, 0644, sysplex_name_show
, sysplex_name_store
);
273 static ssize_t
system_type_show(struct kobject
*kobj
,
274 struct kobj_attribute
*attr
, char *page
)
276 return snprintf(page
, PAGE_SIZE
, "%s\n", system_type
);
279 static ssize_t
system_type_store(struct kobject
*kobj
,
280 struct kobj_attribute
*attr
,
286 rc
= check_string("system_type", buf
);
290 set_string(system_type
, buf
);
295 static struct kobj_attribute system_type_attr
=
296 __ATTR(system_type
, 0644, system_type_show
, system_type_store
);
298 static ssize_t
system_level_show(struct kobject
*kobj
,
299 struct kobj_attribute
*attr
, char *page
)
301 unsigned long long level
= system_level
;
303 return snprintf(page
, PAGE_SIZE
, "%#018llx\n", level
);
306 static ssize_t
system_level_store(struct kobject
*kobj
,
307 struct kobj_attribute
*attr
,
311 unsigned long long level
;
314 level
= simple_strtoull(buf
, &endp
, 16);
323 system_level
= level
;
328 static struct kobj_attribute system_level_attr
=
329 __ATTR(system_level
, 0644, system_level_show
, system_level_store
);
331 static ssize_t
set_store(struct kobject
*kobj
,
332 struct kobj_attribute
*attr
,
333 const char *buf
, size_t len
)
344 static struct kobj_attribute set_attr
= __ATTR(set
, 0200, NULL
, set_store
);
346 static struct attribute
*cpi_attrs
[] = {
347 &system_name_attr
.attr
,
348 &sysplex_name_attr
.attr
,
349 &system_type_attr
.attr
,
350 &system_level_attr
.attr
,
355 static struct attribute_group cpi_attr_group
= {
359 static struct kset
*cpi_kset
;
361 int sclp_cpi_set_data(const char *system
, const char *sysplex
, const char *type
,
366 rc
= check_string("system_name", system
);
369 rc
= check_string("sysplex_name", sysplex
);
372 rc
= check_string("system_type", type
);
376 set_string(system_name
, system
);
377 set_string(sysplex_name
, sysplex
);
378 set_string(system_type
, type
);
379 system_level
= level
;
383 EXPORT_SYMBOL(sclp_cpi_set_data
);
385 static int __init
cpi_init(void)
389 cpi_kset
= kset_create_and_add("cpi", NULL
, firmware_kobj
);
393 rc
= sysfs_create_group(&cpi_kset
->kobj
, &cpi_attr_group
);
395 kset_unregister(cpi_kset
);
400 __initcall(cpi_init
);