1{
2    "$schema": "http://json-schema.org/schema#",
3    "title": "JSON schema for the phosphor-regulators config file",
4    "$id": "https://github.com/openbmc/phosphor-power/tree/master/phosphor-regulators/schema/config_schema.json",
5    "description": "This schema describes the JSON format for the phosphor-regulators configuration file.",
6    "type": "object",
7    "properties":
8    {
9        "comments": {"$ref": "#/definitions/comments" },
10        "rules": {"$ref": "#/definitions/rules" },
11        "chassis": {"$ref": "#/definitions/chassis" }
12    },
13    "required": ["chassis"],
14    "additionalProperties": false,
15    "definitions":
16    {
17        "rule":
18        {
19            "type": "object",
20            "properties":
21            {
22                "comments": {"$ref": "#/definitions/comments" },
23                "id": {"$ref": "#/definitions/id" },
24                "actions": {"$ref": "#/definitions/actions" }
25            },
26            "required": ["id", "actions"],
27            "additionalProperties": false
28        },
29
30        "rules":
31        {
32            "type": "array",
33            "items": {"$ref": "#/definitions/rule" },
34            "minItems": 1
35        },
36
37        "comments":
38        {
39            "type": "array",
40            "items": {"type": "string" },
41            "minItems": 1
42        },
43
44        "id":
45        {
46            "type": "string",
47            "pattern": "^[A-Za-z0-9_]+$"
48        },
49
50        "action":
51        {
52            "type": "object",
53            "properties":
54            {
55                "comments": {"$ref": "#/definitions/comments" },
56                "and": {"$ref": "#/definitions/actions" },
57                "compare_presence": {"$ref": "#/definitions/compare_presence" },
58                "compare_vpd": {"$ref": "#/definitions/compare_vpd" },
59                "i2c_capture_bytes": {"$ref": "#/definitions/i2c_capture_bytes" },
60                "i2c_compare_bit": {"$ref": "#/definitions/i2c_bit" },
61                "i2c_compare_byte": {"$ref": "#/definitions/i2c_byte" },
62                "i2c_compare_bytes": {"$ref": "#/definitions/i2c_bytes" },
63                "i2c_write_bit": {"$ref": "#/definitions/i2c_bit" },
64                "i2c_write_byte": {"$ref": "#/definitions/i2c_byte" },
65                "i2c_write_bytes": {"$ref": "#/definitions/i2c_bytes" },
66                "if": {"$ref": "#/definitions/if" },
67                "log_phase_fault": {"$ref": "#/definitions/log_phase_fault" },
68                "not": {"$ref": "#/definitions/action" },
69                "or": {"$ref": "#/definitions/actions" },
70                "pmbus_read_sensor": {"$ref": "#/definitions/pmbus_read_sensor" },
71                "pmbus_write_vout_command": {"$ref": "#/definitions/pmbus_write_vout_command" },
72                "run_rule": {"$ref": "#/definitions/id" },
73                "set_device": {"$ref": "#/definitions/id" }
74            },
75            "additionalProperties": false,
76            "oneOf": [
77                {"required": ["and"]},
78                {"required": ["compare_presence"]},
79                {"required": ["compare_vpd"]},
80                {"required": ["i2c_capture_bytes"]},
81                {"required": ["i2c_compare_bit"]},
82                {"required": ["i2c_compare_byte"]},
83                {"required": ["i2c_compare_bytes"]},
84                {"required": ["i2c_write_bit"]},
85                {"required": ["i2c_write_byte"]},
86                {"required": ["i2c_write_bytes"]},
87                {"required": ["if"]},
88                {"required": ["log_phase_fault"]},
89                {"required": ["not"]},
90                {"required": ["or"]},
91                {"required": ["pmbus_write_vout_command"]},
92                {"required": ["pmbus_read_sensor"]},
93                {"required": ["run_rule"]},
94                {"required": ["set_device"]}
95            ]
96        },
97
98        "actions":
99        {
100            "type": "array",
101            "items": {"$ref": "#/definitions/action" },
102            "minItems": 1
103        },
104
105        "compare_presence":
106        {
107            "type": "object",
108            "properties":
109            {
110                "fru": {"$ref": "#/definitions/inventory_path" },
111                "value": {"$ref": "#/definitions/boolean_value" }
112            },
113            "required": ["fru", "value"],
114            "additionalProperties": false
115        },
116
117        "inventory_path":
118        {
119            "type": "string",
120            "minLength": 1
121        },
122
123        "boolean_value":
124        {
125            "type": "boolean"
126        },
127
128        "compare_vpd":
129        {
130            "type": "object",
131            "properties":
132            {
133                "fru": {"$ref": "#/definitions/inventory_path" },
134                "keyword": {"$ref": "#/definitions/keyword" },
135                "value": {"$ref": "#/definitions/string_value" },
136                "byte_values": {"$ref": "#/definitions/byte_values_min0" }
137            },
138            "required": ["fru", "keyword"],
139            "oneOf": [
140                {"required": ["value"]},
141                {"required": ["byte_values"]}
142            ],
143            "additionalProperties": false
144        },
145
146        "keyword":
147        {
148            "type": "string",
149            "enum": ["CCIN", "Manufacturer", "Model", "PartNumber", "HW"]
150        },
151
152        "string_value":
153        {
154            "type": "string"
155        },
156
157        "i2c_capture_bytes":
158        {
159            "type": "object",
160            "properties":
161            {
162                "register": {"$ref": "#/definitions/register" },
163                "count": {"$ref": "#/definitions/byte_count" }
164            },
165            "required": ["register", "count"],
166            "additionalProperties": false
167        },
168
169        "i2c_bit":
170        {
171            "type": "object",
172            "properties":
173            {
174                "register": {"$ref": "#/definitions/register" },
175                "position": {"$ref": "#/definitions/position" },
176                "value": {"$ref": "#/definitions/bit_value" }
177            },
178            "required": ["register", "position","value"],
179            "additionalProperties": false
180        },
181
182        "register":
183        {
184            "type": "string",
185            "pattern": "^0x[0-9A-Fa-f]{2}$"
186        },
187
188        "position":
189        {
190            "type": "integer",
191            "minimum": 0,
192            "maximum": 7
193        },
194
195        "bit_value":
196        {
197            "type": "integer",
198            "minimum": 0,
199            "maximum": 1
200        },
201
202        "i2c_byte":
203        {
204            "type": "object",
205            "properties":
206            {
207                "register": {"$ref": "#/definitions/register" },
208                "value": {"$ref": "#/definitions/byte_value" },
209                "mask": {"$ref": "#/definitions/byte_mask" }
210            },
211            "required": ["register", "value"],
212            "additionalProperties": false
213        },
214
215        "byte_value":
216        {
217            "type": "string",
218            "pattern": "^0x[0-9A-Fa-f]{2}$"
219        },
220
221        "byte_mask":
222        {
223            "type": "string",
224            "pattern": "^0x[0-9A-Fa-f]{2}$"
225        },
226
227        "byte_count":
228        {
229            "type": "integer",
230            "minimum": 1
231        },
232
233        "i2c_bytes":
234        {
235            "type": "object",
236            "properties":
237            {
238                "register": {"$ref": "#/definitions/register" },
239                "values": {"$ref": "#/definitions/byte_values" },
240                "masks": {"$ref": "#/definitions/byte_masks" }
241            },
242            "required": ["register", "values"],
243            "additionalProperties": false
244        },
245
246        "byte_values":
247        {
248            "type": "array",
249            "items": {"$ref": "#/definitions/byte_value" },
250            "minItems": 1
251        },
252
253        "byte_values_min0":
254        {
255            "type": "array",
256            "items": {"$ref": "#/definitions/byte_value" },
257            "minItems": 0
258        },
259
260        "byte_masks":
261        {
262            "type": "array",
263            "items": {"$ref": "#/definitions/byte_mask" },
264            "minItems": 1
265        },
266
267        "if":
268        {
269            "type": "object",
270            "properties":
271            {
272                "condition": {"$ref": "#/definitions/action" },
273                "then": {"$ref": "#/definitions/actions" },
274                "else": {"$ref": "#/definitions/actions" }
275            },
276            "required": ["condition", "then"],
277            "additionalProperties": false
278        },
279
280        "log_phase_fault":
281        {
282            "type": "object",
283            "properties":
284            {
285                "type": {"$ref": "#/definitions/phase_fault_type" }
286            },
287            "required": ["type"],
288            "additionalProperties": false
289        },
290
291        "phase_fault_type":
292        {
293            "type": "string",
294            "enum": ["n+1", "n"]
295        },
296
297        "pmbus_write_vout_command":
298        {
299            "type": "object",
300            "properties":
301            {
302                "volts": {"$ref": "#/definitions/volts" },
303                "format": {"$ref": "#/definitions/write_vout_format" },
304                "exponent": {"$ref": "#/definitions/exponent" },
305                "is_verified": {"$ref": "#/definitions/is_verified" }
306            },
307            "required": ["format"],
308            "additionalProperties": false
309        },
310
311        "volts":
312        {
313            "type": "number"
314        },
315
316        "write_vout_format":
317        {
318            "type": "string",
319            "enum": ["linear"]
320        },
321
322        "exponent":
323        {
324            "type": "integer"
325        },
326
327        "is_verified":
328        {
329            "type": "boolean"
330        },
331
332        "pmbus_read_sensor":
333        {
334            "type": "object",
335            "properties":
336            {
337                "type": {"$ref": "#/definitions/pmbus_read_sensor_type" },
338                "command": {"$ref": "#/definitions/pmbus_read_sensor_command" },
339                "format": {"$ref": "#/definitions/read_sensor_format" },
340                "exponent": {"$ref": "#/definitions/exponent" }
341            },
342            "required": ["type", "command", "format"],
343            "additionalProperties": false
344        },
345
346        "pmbus_read_sensor_type":
347        {
348            "type": "string",
349            "enum": ["iout", "iout_peak", "iout_valley", "pout", "temperature", "temperature_peak", "vout", "vout_peak", "vout_valley"]
350        },
351
352        "pmbus_read_sensor_command":
353        {
354            "type": "string",
355            "pattern": "^0x[0-9a-fA-F]{2}$"
356        },
357
358        "read_sensor_format":
359        {
360            "type": "string",
361            "enum": ["linear_11", "linear_16"]
362        },
363
364        "chassis_object":
365        {
366            "type": "object",
367            "properties":
368            {
369                "comments": {"$ref": "#/definitions/comments" },
370                "number": {"$ref": "#/definitions/number" },
371                "inventory_path": {"$ref": "#/definitions/inventory_path" },
372                "devices": {"$ref": "#/definitions/devices" }
373            },
374            "required": ["number", "inventory_path"],
375            "additionalProperties": false
376        },
377
378        "chassis":
379        {
380            "type": "array",
381            "items": {"$ref": "#/definitions/chassis_object" },
382            "minItems": 1
383        },
384
385        "number":
386        {
387            "type": "integer",
388            "minimum": 1
389        },
390
391        "device":
392        {
393            "type": "object",
394            "properties":
395            {
396                "comments": {"$ref": "#/definitions/comments" },
397                "id": {"$ref": "#/definitions/id" },
398                "is_regulator": {"$ref": "#/definitions/is_regulator" },
399                "fru": {"$ref": "#/definitions/inventory_path" },
400                "i2c_interface": {"$ref": "#/definitions/i2c_interface" },
401                "presence_detection": {"$ref": "#/definitions/presence_detection" },
402                "configuration": {"$ref": "#/definitions/configuration" },
403                "phase_fault_detection": {"$ref": "#/definitions/phase_fault_detection" },
404                "rails": {"$ref": "#/definitions/rails" }
405            },
406            "required": ["id", "is_regulator", "fru", "i2c_interface"],
407            "if":
408            {
409                "properties": { "is_regulator": { "const": false } }
410            },
411            "then":
412            {
413                "not": {
414                    "anyOf": [
415                        { "required": ["phase_fault_detection"] },
416                        { "required": ["rails"] }
417                    ]
418                }
419            },
420            "additionalProperties": false
421        },
422
423        "devices":
424        {
425            "type": "array",
426            "items": {"$ref": "#/definitions/device" },
427            "minItems": 1
428        },
429
430        "is_regulator":
431        {
432            "type": "boolean"
433        },
434
435        "i2c_interface":
436        {
437            "type": "object",
438            "properties":
439            {
440                "bus": {"$ref": "#/definitions/bus" },
441                "address": {"$ref": "#/definitions/address" }
442            },
443            "required": ["bus", "address"],
444            "additionalProperties": false
445        },
446
447        "bus":
448        {
449            "type": "integer",
450            "minimum": 0
451        },
452
453        "address":
454        {
455            "type": "string",
456            "pattern": "^0x[0-9A-Fa-f]{2}$"
457        },
458
459        "presence_detection":
460        {
461            "type": "object",
462            "properties":
463            {
464                "comments": {"$ref": "#/definitions/comments" },
465                "rule_id": {"$ref": "#/definitions/id" },
466                "actions": {"$ref": "#/definitions/actions" }
467            },
468            "additionalProperties": false,
469            "oneOf": [
470                {"required": ["rule_id"]},
471                {"required": ["actions"]}
472            ]
473        },
474
475        "configuration":
476        {
477            "type": "object",
478            "properties":
479            {
480                "comments": {"$ref": "#/definitions/comments" },
481                "volts": {"$ref": "#/definitions/volts" },
482                "rule_id": {"$ref": "#/definitions/id" },
483                "actions": {"$ref": "#/definitions/actions" }
484            },
485            "additionalProperties": false,
486            "oneOf": [
487                {"required": ["rule_id"]},
488                {"required": ["actions"]}
489            ]
490        },
491
492        "phase_fault_detection":
493        {
494            "type": "object",
495            "properties":
496            {
497                "comments": {"$ref": "#/definitions/comments" },
498                "device_id": {"$ref": "#/definitions/id" },
499                "rule_id": {"$ref": "#/definitions/id" },
500                "actions": {"$ref": "#/definitions/actions" }
501            },
502            "additionalProperties": false,
503            "oneOf": [
504                {"required": ["rule_id"]},
505                {"required": ["actions"]}
506            ]
507        },
508
509        "rail":
510        {
511            "type": "object",
512            "properties":
513            {
514                "comments": {"$ref": "#/definitions/comments" },
515                "id": {"$ref": "#/definitions/id" },
516                "configuration": {"$ref": "#/definitions/configuration" },
517                "sensor_monitoring": {"$ref": "#/definitions/sensor_monitoring" }
518            },
519            "required": ["id"],
520            "additionalProperties": false
521        },
522
523        "rails":
524        {
525            "type": "array",
526            "items": {"$ref": "#/definitions/rail" },
527            "minItems": 1
528        },
529
530        "sensor_monitoring":
531        {
532            "type": "object",
533            "properties":
534            {
535                "comments": {"$ref": "#/definitions/comments" },
536                "rule_id": {"$ref": "#/definitions/id" },
537                "actions": {"$ref": "#/definitions/actions" }
538            },
539            "additionalProperties": false,
540            "oneOf": [
541                {"required": ["rule_id"]},
542                {"required": ["actions"]}
543            ]
544        }
545    }
546}
547