Copyright © 2014 Nvidia, Inc.
The Regpict library draws register pictures in specifications. An example such figure is shown in Figure 1.
This library consists of two levels:
Converts a JSON formatted description of a hardware register into the corresponding SVG diagram.
This layer supports inheritance.
These extract information from a variety of input formats and produce JSON usable by the JSON to SVG conversion layer. Input formats include:
<table class="regpict-pcisig">...</table>
as used in recent [PCISIG] specifications.
<pre class="regpict-json">...</pre>
containing the JSON code.<pre class="regpict-refman">...</pre>
containing Nvidia refman formatted text.
Using the JSON extraction layer is optional. The JSON to SVG conversion layer can be used standalone.
The generated SVG is designed to be styled using CSS. Proper representation requires some CSS. A minimal CSS file is provided as well as a more complete example. Section 3 describes the classes contained in the generated SVG.
The initial implementation is in JavaScript. This version was integrated into a fork [RESPEC-Fork] of the respec library [RESPEC].
A version in Ruby that works as a plugin filter for [ASCIIDOCTOR] is anticipated.
This document is merely a public working draft of a potential specification. It has no official standing of any kind and does not represent the support or consensus of any standards organisation.
<figure class="register"> <pre class="json"> { "fields": { "field 4:0": { "msb": 4, "lsb": 0, "attr": "ro" }, "bit9": { "msb": 9, "value": "1" }, "bit10": { "lsb": 10, "value": "0" }, "bit11": { "lsb": 11 }, "bit 12:15": { "lsb": 12, "msb": 15, "value": "value" }, "byte": { "lsb": 16, "msb": 31, "value": [ "A", "B", "C", "D", "E", "F", "G", "H"] } } } </pre> <figcaption>JSON Register Example</figcaption> </figure>
The JSON intermediate format contains a collection of properties related to the overall register as well as a fields property with details for each register field. The each property of fields describes the corresponding register field.
The following register properties are defined:
{ }
.
The following properties are defined for register fields:
Name of the field. If the name fits in the field box and no value is provided for the field, the name is drawn in the field box, centered horizontally, with the top edge of the name text at cellNameTop. Otherwise, the field name is drawn to the right of bit visibleLSB with a line connecting the field name to the middle of the bit field.
If name is not specified, the default is the property name of the field within the fields property of the register. Note: all fields in Figure 1 do not have a name property.
id
attribute for the
<g>
element in the generated SVG.
If this property is not explicitly defined and field is not isUnused, an
id
attribute will be be created for the field using rules defined in
Section 3.4.
xxx
. This permits styling of register fields based on field attribute (Read Only, Read Write, etc.). This value is converted to lower case so it's irrelevant what case is used for this property. This property must be a valid class name (e.g. no spaces, etc.). Common values are: rw, rws, ro, ros, rw1c, rw1cs, rw1s, rw1ss, wo, wos, hardwired, fixed, hwinit, rsvd, rsvdp, rsvdz, reserved, unused, and other. The default value of
attr is "other".
<g>
element. A good application for the
addClass property is to highlight particular fields, when this highlighting is not an intrinsic property of the field. For example, if the same figure is used in multiple places, with each usage explaining some of the fields, the
addClass property can be used to highlight the appropriate fields. Intrinsic properties of a field are better indicated through the
attr property.
This section describes the structure of the generated SVG. Knowing this structure permits more flexible styling of the resulting diagram using CSS.
The generated SVG contains a
<g>
element for every field. This includes fields that are explicitly defined as well as fields that are created to represent unused register bits.
Regpict will generate an External Field when the field name doesn't fit in the bit field box or the field has a value property.
An example External Field is shown below. This is the bit 12:15 field from Figure 1.
<g id="regpict-json-register-example-bit-12-15" class="regFieldExternal regAttr_other regLink regFieldExternal1"> <text x="358" y="36" class="regBitNumEnd">12</text> <text x="298" y="36" class="regBitNumStart">15</text> <line x1="360" y1="40" x2="360" y2="26.5" class="regBitNumLine_Hide"></line> <line x1="296" y1="40" x2="296" y2="26.5" class="regBitNumLine"></line> <rect x="296" y="40" width="64" height="32" class="regFieldBox"></rect> <line x1="344" y1="64" x2="344" y2="72" class="regFieldBox"></line> <line x1="328" y1="64" x2="328" y2="72" class="regFieldBox"></line> <line x1="312" y1="64" x2="312" y2="72" class="regFieldBox"></line> <text x="328" y="20" class="regBitWidth">4 bits</text> <text x="568" y="152" class="regFieldName">bit 12:15</text> <text x="328" y="56" class="regFieldValue">value</text> <path d="M296,72l32,4L360,72" class="regBitBracket" fill="none"></path> <path d="M328,76V147.5H566.4" class="regBitLine" fill="none"></path> </g>
Regpict will generate an Internal Field when the field name fits in the bit field box and there is no value property.
An example Internal Field is shown below. This is the field 4:0 field from Figure 1.
<g id="regpict-json-register-example-field-4-0" class="regFieldInternal regAttr_ro regLink"> <text x="550" y="36" class="regBitNumEnd">0</text> <text x="474" y="36" class="regBitNumStart">4</text> <line x1="552" y1="40" x2="552" y2="26.5" class="regBitNumLine"></line> <line x1="472" y1="40" x2="472" y2="26.5" class="regBitNumLine"></line> <rect x="472" y="40" width="80" height="32" class="regFieldBox"></rect> <line x1="536" y1="64" x2="536" y2="72" class="regFieldBox"></line> <line x1="520" y1="64" x2="520" y2="72" class="regFieldBox"></line> <line x1="504" y1="64" x2="504" y2="72" class="regFieldBox"></line> <line x1="488" y1="64" x2="488" y2="72" class="regFieldBox"></line> <text x="512" y="20" class="regBitWidth">5 bits</text> <text x="512" y="56" class="regFieldName">field 4:0</text> </g>
<g>
element: class
attributesThe generated SVG has a variety of classes available. This allows customizing the styling of the diagram using CSS.
The following classes are defined:
<g>
element to indicate an Internal Field.
<g>
element to indicate and External Field.
<g>
element of an External Field. The two least significant
External Fields have regFieldExternal0. The next two
External Fields have
regFieldExternal1. The pattern repeats with next two
External Fields have regFieldExternal0, followed by two with
regFieldExternal1. These classes can be used to format the lines differently to enhance readability.
<g>
element to indicate a defined field that can be referenced externally. These fields have an
id
attribute).
<g>
element to indicate that the field is partially visible because its
lsb is less than visibleLSB.
<g>
element to indicate that the field is partially visible because its
msb is greater than visibleMSB.
<g>
element to indicate that the field is not visible either because its
lsb is greater than visibleMSB or its msb is less than visibleLSB.
xxx
<g>
element to convey the attributes of the corresponding field.
The xxx
is the attr value converted to lower case.
<g>
element of an Internal Field to indicate that the
isUnused property was present and
true
. Not applicable to an External Field.
<text>
element that contains the msb bit number of the field.
Used only for multi-bit fields.
<text>
element that contains the lsb bit number of the field.
Used only for multi-bit fields.
<text>
element that contains the bit number of the field.
Used only for single bit fields.
<line>
element that represents the line adjacent to the lsb and msb bit numbers of the field.
<g>
element.
<rect>
element that represents the bit field box.
<line>
element that represents the bit divider lines within the bit field box.
Used only for multi-bit fields.
<text>
element that contains the field name.
<text>
element that contains the width of the field.
This element should be hidden by default and should become visible when the user hovers over the
<g>
element.
<text>
element that contains the field value.
Used for all fields that contain a value property.
<text>
element that contains a single bit of the field value.
Used for fields that contain individual bit field values.
These fields also have class regFieldValue.
N
<text>
element that contains bit
N
of the field value.
Permits formatting individual bit values differently.
<text>
element that contains the value of the most significant bit of the field
value.
Permits formatting the msb value differently.
The lsb equivalent is regBitFieldValue-0.
<path>
element of an
External Field that is the bracket immediately below the bit field box. Not applicable to Internal Fields.
<path>
element of an
External Field that connects the bracket to the field name. Not applicable to Internal Fields.
<g>
element: id
attribute
Regpict will generate a unique
id
attribute for most fields.
No id
is generated for unused fields (i.e. fields that have an
isUnused property with the value true
.
All other fields have an id
attribute generated as follows:
id
attribute already present the document.
-N
“ where ”N
“ a is the smallest integer value greater 0 that is not already used in the document.
For example, for the preliminary id “regpict-foo” is already present, the next one is “regpict-foo-1”, followed by “regpict-foo-2”, and so forth.
Unused bits in a register cause a field to be invented by Regpict.
This field has the following properties:
true
This section describes usage of the regpict feature in Steve Glaser's fork of respec [RESPEC-Fork].
There are 4 ways to use regpict:
id
attribute of the <figure> element, removing the text “fig-” from the beginning of the value.
title
attribute of the <figure>.This value is then sanitized by:
id
attributeIf the <figure> does not have an
id
attribute, it is set to “fig-figName” where figName is the
figName property defined in Section 4.1.1 Figure figName property.
data-json
attributedata-json
attribute, it's value is parsed and merged into the figure's JSON.
data-width
attributedata-width
attribute, it's value becomes the
width property of the figure's JSON.
data-unused
attributedata-unused
attribute, it's value becomes the
defaultUnused property of the figure's JSON.
data-href
attributedata-href
attribute, it's value becomes the
href property of the figure's JSON.
data-table
attributedata-table
attribute, it's value becomes the
table property of the figure's JSON.
data-register
attributedata-register
attribute, it's value becomes the
register property of the figure's JSON.
If the <figure> contains one or more <pre class="json">, <div class="json">, or <span class="json"> elements, these elements are parsed and combined and the resulting figure is drawn. These elements are hidden as they are parsed (class “hide” added so they can be hidden by css).
If the JSON does not define a figName property, the <figcaption> value is used to invent one.
This situation is shown in Figure 2 and Example 4
<figure class="register" id="fig-json-directly-in-figure"> <pre class="json"> { "fields": { "foo": { "lsb": 0, "msb": 7 } } } </pre> <figcaption>JSON directly in <figure></figcaption> </figure>
If the <figure> contains one or more <pre class="render">, <div class="render">, or <span class="render"> elements, these elements are parsed a figure is drawn for each such element. This can result in a single <figure> element having multiple figure diagrams. This is particularly useful in conjunction with visibleLSB and visibleMSB to display very wide registers conveniently. These elements are hidden as they are parsed (class “hide” added so they can be hidden by css).
If the <pre>, <div>, or <span> element has the
data-parents
attribute, this contains a list of one or more locators for external field definitions. The parents are merged into a copy of the <figure> JSON, in the order shown and then the JSON in the element is merged in. The figure is drawn with the resulting JSON. The JSON associated with the <figure> element is not affected.
If the JSON does not define a figName property, the <figcaption> value is used to invent one.
This situation is shown in Figure 3 and Example 4
<pre id="pre-external-json" class="json"> { "width": 64, "fields": { "lowByte": { "lsb": 0, "msb": 7 }, "highByte": { "lsb": 56, "msb": 63 }, "middle": { "lsb": 28, "msb": 39 } } } </pre> <figure class="register"> <pre class="render" data-parents="pre-external-json">{ }</pre> <pre class="render" data-parents="pre-external-json"> { "visibleLSB": 31 }</pre> <pre class="render" data-parents="pre-external-json"> { "visibleMSB": 32 }</pre> <figcaption>JSON outside the <figure></figcaption> </figure>
If the <figure> element has the class pcisig_reg
(in addition to the class
register
), and the
table property is defined in the JSON the <table> element referenced by the
table property is parsed and merged into the figure's JSON.
The table property can either be specified directly in the JSON or via the
data-table
attribute on the <figure>.
The underlying <table> can have any formatting. No specific class
attribute is required.
The first column contains the bit location of the field. This determines the lsb and msb properties of the field. The column cell contains either an integer or a pair of integers separated by a colon (e.g. “9”, “15:8” or “8:15”). If two numbers are shown, the MSB is usually first, but this is not required.
The second column determines the name property of the field. It also contains a description of the field. The name property is derived from:
<code>
or
<dfn>
element.
<code>
or
<dfn>
element is present, the first word of the column cell.
The third column determines the attr property of the field. This field is not case sensitive. Valid values are shown in the list below. If the third column does not on of the items, the attr property is “other”.
It the third column matches one of the items marked “(unused)”, the isUnused property is set totrue
, otherwise the
isUnused property is not set.
is shown in and is based on PCISIG Example.
Bit Location | Description | Attr |
---|---|---|
3:0 | field3_0 this field is shown as <code>field3_0</code> . |
RO |
4 | field_4 this field is shown as
<dfn;>field_4</dfn> .
|
rw |
9 | This is the description. | ros |
16:19 | bits_16_19 this field is shown as
<dfn class="field">bits_16_19</dfn> .
Because the <dfn> has the class field, it is automatically linked to the corresponding field in the figure.
Similarly, that field in the figure is linked back to this definition.
|
rw |
24:31 | upper_bits | hardwired |
If the <figure> element has the class nv_refman
(in addition to the class
register
), and the href property is defined in the JSON, the file referenced by the
href property is read and the register defined by the register property is drawn as a figure.
The href and register properties can either be specified directly in the JSON or via the
data-href
and data-register
attributes.
The referenced file MUST be formatted as an Nvidia refman file and MUST contain a register of the corresponding name.
The width property is determined from the refman definition unless it is already specified in JSON.
The attributes of each field are determined from the refman definition. These will be one of "ro", "rw", or "wo".