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