1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
|
/* IBM_PROLOG_BEGIN_TAG */
/* This is an automatically generated prolog. */
/* */
/* $Source: src/usr/sio/test/sioddtest.H $ */
/* */
/* OpenPOWER HostBoot Project */
/* */
/* Contributors Listed Below - COPYRIGHT 2014,2015 */
/* [+] International Business Machines Corp. */
/* */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); */
/* you may not use this file except in compliance with the License. */
/* You may obtain a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, software */
/* distributed under the License is distributed on an "AS IS" BASIS, */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or */
/* implied. See the License for the specific language governing */
/* permissions and limitations under the License. */
/* */
/* IBM_PROLOG_END_TAG */
#ifndef __SIODDTEST_H
#define __SIODDTEST_H
/**
* @file sioddtest.H
*
* @brief Test case for SuperIO Driver
*/
#include <devicefw/driverif.H>
#include <cxxtest/TestSuite.H>
#include <errl/errlmanager.H>
#include <errl/errlentry.H>
#include <devicefw/userif.H>
#include <sys/time.h>
#include <list>
#include <targeting/common/attributes.H>
#include <sio/sio.H>
#include "../siodd.H"
const uint8_t CTLREG_04 = 0x04;
const uint32_t SPIC_BASE_ADDR_AHB = 0x1E630000;
class SioDDTest : public CxxTest::TestSuite
{
public:
/**
* @brief Test SIO access
* Use a SIO scratch register to verify reads and writes
*/
void test_SIO(void)
{
errlHndl_t l_err = NULL;
size_t l_len = sizeof(uint8_t);
mutex_t l_lock = Singleton<SioDD>::instance().iv_sio_mutex;
mutex_lock(&l_lock);
// Read SIO to BMC scratch reg 1,2 and save off values
uint8_t scratch1 = 0;
l_err = deviceOp( DeviceFW::READ,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(scratch1),
l_len,
DEVICE_SIO_ADDRESS(SIO::SUART1, SIO::SIO_SCRATCH_REG1));
if( l_err )
{
TS_FAIL("SioDDTest::test_SIO> read from SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
uint8_t scratch2 = 0;
l_err = deviceOp( DeviceFW::READ,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(scratch2),
l_len,
DEVICE_SIO_ADDRESS(SIO::SUART1, SIO::SIO_SCRATCH_REG2));
if( l_err )
{
TS_FAIL("SioDDTest::test_SIO> read from SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
// Write test patterns into registers
uint8_t testdata = 0xA5;
l_err = deviceOp( DeviceFW::WRITE,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(testdata),
l_len,
DEVICE_SIO_ADDRESS(SIO::SUART1, SIO::SIO_SCRATCH_REG1));
if( l_err )
{
TS_FAIL("SioDDTest::test_SIO> write to SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
testdata = 0x12;
l_err = deviceOp( DeviceFW::WRITE,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(testdata),
l_len,
DEVICE_SIO_ADDRESS(SIO::SUART1, SIO::SIO_SCRATCH_REG2));
if( l_err )
{
TS_FAIL("SioDDTest::test_SIO> write to SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
// Read the data back and compare to expected results
l_err = deviceOp( DeviceFW::READ,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(testdata),
l_len,
DEVICE_SIO_ADDRESS(SIO::SUART1, SIO::SIO_SCRATCH_REG1));
if( l_err )
{
TS_FAIL("SioDDTest::test_SIO> read from SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
if( testdata != 0xA5 )
{
TS_FAIL("SioDDTest::test_SIO> Data mismatch on SIO 0x21\
: Exp=0xA5, Act=%.2X", testdata);
}
l_err = deviceOp( DeviceFW::READ,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(testdata),
l_len,
DEVICE_SIO_ADDRESS(SIO::SUART1, SIO::SIO_SCRATCH_REG2));
if( l_err )
{
TS_FAIL("SioDDTest::test_SIO> read from SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
if( testdata != 0x12 )
{
TS_FAIL("SioDDTest::test_SIO> Data mismatch on SIO 0x22 :/\
Exp=0x12, Act=%.2X", testdata);
}
// Restore the original data
l_err = deviceOp( DeviceFW::WRITE,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(scratch1),
l_len,
DEVICE_SIO_ADDRESS(SIO::SUART1, SIO::SIO_SCRATCH_REG1));
if( l_err )
{
TS_FAIL("SioDDTest::test_SIO> write to SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
l_err = deviceOp( DeviceFW::WRITE,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(scratch2),
l_len,
DEVICE_SIO_ADDRESS(SIO::SUART1, SIO::SIO_SCRATCH_REG2));
if( l_err )
{
TS_FAIL("SioDDTest::test_SIO> write to SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
mutex_unlock(&l_lock);
}
/**
* @brief Concurrency test for SIO registers using devices Key Board
* Controller and MailBox
*/
void test_concurrency()
{
mutex_t l_lock = Singleton<SioDD>::instance().iv_sio_mutex;
mutex_lock(&l_lock);
errlHndl_t l_err = NULL;
uint8_t l_data;
size_t l_len = sizeof(l_data);
//Enable additional SIO test devices 5 and E
l_data = SIO::ENABLE_DEVICE;
l_err = deviceOp( DeviceFW::WRITE,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(l_data),
l_len,
DEVICE_SIO_ADDRESS(SIO::KBC, 0x30));
if( l_err )
{
TS_FAIL("SioDDTest::SIO_concurrency> write to SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
l_err = deviceOp( DeviceFW::WRITE,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(l_data),
l_len,
DEVICE_SIO_ADDRESS(SIO::MB, 0x30));
if( l_err )
{
TS_FAIL("SioDDTest::SIO_concurrency> write to SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
//Read current values from devices
//KBC
uint8_t kbc_base_add_msb = 0;
l_err = deviceOp( DeviceFW::READ,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(kbc_base_add_msb),
l_len,
DEVICE_SIO_ADDRESS(SIO::KBC, 0x60));
if( l_err )
{
TS_FAIL("SioDDTest::SIO_concurrency> read from SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
//MB
uint8_t mb_base_add_msb = 0;
l_err = deviceOp( DeviceFW::READ,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(mb_base_add_msb),
l_len,
DEVICE_SIO_ADDRESS(SIO::MB, 0x60));
if( l_err )
{
TS_FAIL("SioDDTest::SIO_concurrency> read from SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
//Write new values to registers 0x60
//KBC
uint8_t testdata1 = 0xAA;
l_err = deviceOp( DeviceFW::WRITE,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(testdata1),
l_len,
DEVICE_SIO_ADDRESS(SIO::KBC, 0x60));
if( l_err )
{
TS_FAIL("SioDDTest::SIO_concurrency> write to SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
//MB
uint8_t testdata2 = 0x05;
l_err = deviceOp( DeviceFW::WRITE,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(testdata2),
l_len,
DEVICE_SIO_ADDRESS(SIO::MB, 0x60));
if( l_err )
{
TS_FAIL("SioDDTest::SIO_concurrency> write to SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
//Read and compare
uint8_t testdata;
l_err = deviceOp( DeviceFW::READ,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(testdata),
l_len,
DEVICE_SIO_ADDRESS(SIO::KBC, 0x60));
if( l_err )
{
TS_FAIL("SioDDTest::SIO_concurrency> read from SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
if( testdata != 0xAA )
{
TS_FAIL("SioDDTest::SIO_concurreny> Data mismatch on SIO device KBC\
reg 0x60 : Exp=0xAA, Act=%.2X", testdata);
}
l_err = deviceOp( DeviceFW::READ,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(testdata),
l_len,
DEVICE_SIO_ADDRESS(SIO::MB, 0x60));
if( l_err )
{
TS_FAIL("SioDDTest::SIO_concurrency> read from SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
if( testdata != 0x05 )
{
TS_FAIL("SioDDTest::SIO_concurreny> Data mismatch on SIO device MB\
reg 0x60 : Exp=0x05, Act=%.2X", testdata);
}
//Write original data back
l_err = deviceOp( DeviceFW::WRITE,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(kbc_base_add_msb),
l_len,
DEVICE_SIO_ADDRESS(SIO::KBC, 0x60));
if( l_err )
{
TS_FAIL("SioDDTest::SIO_concurrency> write to SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
//MB
l_err = deviceOp( DeviceFW::WRITE,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(mb_base_add_msb),
l_len,
DEVICE_SIO_ADDRESS(SIO::MB, 0x60));
if( l_err )
{
TS_FAIL("SioDDTest::SIO_concurrency> write to SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
mutex_unlock(&l_lock);
}
/** @brief test simultaneous accesses to same logical device
*/
void test_same_dev()
{
uint8_t l_data;
errlHndl_t l_err = NULL;
size_t l_len = sizeof(l_data);
mutex_t l_lock = Singleton<SioDD>::instance().iv_sio_mutex;
mutex_lock(&l_lock);
//enable device Key Board Controller
l_data = SIO::ENABLE_DEVICE;
l_err = deviceOp( DeviceFW::WRITE,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(l_data),
l_len,
DEVICE_SIO_ADDRESS(SIO::KBC, 0x30));
if( l_err )
{
TS_FAIL("SioDDTest::test_same_dev> write to SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
//Read value at key board controller, reg 0x60
uint8_t current_data = 0;
l_err = deviceOp( DeviceFW::READ,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(current_data),
l_len,
DEVICE_SIO_ADDRESS(SIO::KBC, 0x60));
if( l_err )
{
TS_FAIL("SioDDTest::test_same_dev> read from SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
//Write new test value to key board controller, reg 0x60
uint8_t test_data = 0x10;
l_err = deviceOp( DeviceFW::WRITE,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(test_data),
l_len,
DEVICE_SIO_ADDRESS(SIO::KBC, 0x60));
if( l_err )
{
TS_FAIL("SioDDTest::test_same_dev> write to SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
//Read and compare
l_err = deviceOp( DeviceFW::READ,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(test_data),
l_len,
DEVICE_SIO_ADDRESS(SIO::KBC, 0x60));
if( l_err )
{
TS_FAIL("SioDDTest::test_same_dev> read from SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
if(test_data != 0x10)
{
TS_FAIL("SioDDTest::test_same_dev> Data mismatch on SIO KBC, 0x60\
: Exp=0x10, Act=%.2X", test_data);
}
//Write back original data
l_err = deviceOp( DeviceFW::WRITE,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(current_data),
l_len,
DEVICE_SIO_ADDRESS(SIO::KBC, 0x60));
if( l_err )
{
TS_FAIL("SioDDTest::test_same_dev> write to SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
mutex_unlock(&l_lock);
}
/**
* @brief AHB_SIO access
* Read and write data to the SPI Control register
*/
void test_AHB_SIO( void )
{
errlHndl_t l_err = NULL;
uint32_t l_lpc_addr;
size_t l_len = sizeof(uint32_t);
mutex_t l_lock = Singleton<SioDD>::instance().iv_sio_mutex;
mutex_lock(&l_lock);
uint32_t first = 0;
l_lpc_addr = CTLREG_04 | SPIC_BASE_ADDR_AHB;
l_err = deviceOp( DeviceFW::READ,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(first),
l_len,
DEVICE_AHB_SIO_ADDRESS(l_lpc_addr));
if( l_err )
{
TS_FAIL("SioDDTest::test_AHB_SIO> read from AHB_SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
uint32_t data1 = 0x12345678;
l_err = deviceOp( DeviceFW::WRITE,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(data1),
l_len,
DEVICE_AHB_SIO_ADDRESS(l_lpc_addr));
if( l_err )
{
TS_FAIL("SioDDTest::test_AHB_SIO> write to AHB_SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
l_err = deviceOp( DeviceFW::READ,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(data1),
l_len,
DEVICE_AHB_SIO_ADDRESS(l_lpc_addr));
if( l_err )
{
TS_FAIL("SioDDTest::test_AHB_SIO> read from AHB_SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
if( data1 != 0x12345678 )
{
TS_FAIL("SioDDTest::test_SPIC> Unexpected result of %.8X\
(exp 0x12345678)",data1);
}
//put back the original
l_err = deviceOp( DeviceFW::WRITE,
TARGETING::MASTER_PROCESSOR_CHIP_TARGET_SENTINEL,
&(first),
l_len,
DEVICE_AHB_SIO_ADDRESS(l_lpc_addr));
if( l_err )
{
TS_FAIL("SioDDTest::test_AHB_SIO> write to AHB_SIO failed");
errlCommit(l_err,SIO_COMP_ID);
}
mutex_unlock(&l_lock);
}
};
#endif
|