summaryrefslogtreecommitdiffstats
path: root/hw/nx-rng.c
diff options
context:
space:
mode:
authorDan Streetman <ddstreet@ieee.org>2015-02-17 15:38:54 -0500
committerStewart Smith <stewart@linux.vnet.ibm.com>2015-02-19 12:20:28 +1100
commitd9ee934722fbdb72405989b0ada101ac4a717cb2 (patch)
tree726a928306cc6a0a672e2962efae62faab12bc3c /hw/nx-rng.c
parent34b3786798f09650c4bf0d0ff92654fdb79748d3 (diff)
downloadtalos-skiboot-d9ee934722fbdb72405989b0ada101ac4a717cb2.tar.gz
talos-skiboot-d9ee934722fbdb72405989b0ada101ac4a717cb2.zip
add nx-842 coproc support
Add support for the 842 hw memory compression engine in the NX Coprocessor. This moves the existing RNG support into its own nx-rng.c file, adds 842 support in a nx-842.c file, and creates a nx-crypto.c file to configure and disable the crypto engines (which are not supported yet). New nodes are created for each 842 engine found. This does not actually process any of the data or drive the 842 engines, it only configures registers to set up and enable/disable the engines appropriately, and creates new nodes so the OS can drive the 842 engines. Signed-off-by: Dan Streetman <ddstreet@ieee.org> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'hw/nx-rng.c')
-rw-r--r--hw/nx-rng.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/hw/nx-rng.c b/hw/nx-rng.c
new file mode 100644
index 00000000..9cc5317f
--- /dev/null
+++ b/hw/nx-rng.c
@@ -0,0 +1,99 @@
+/* Copyright 2013-2015 IBM 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.
+ */
+
+
+
+#include <skiboot.h>
+#include <xscom.h>
+#include <io.h>
+#include <cpu.h>
+#include <nx.h>
+
+void nx_create_rng_node(struct dt_node *node)
+{
+ u64 bar, cfg;
+ u64 xbar, xcfg;
+ u32 pb_base;
+ u32 gcid;
+ u64 rng_addr, rng_len, len;
+ struct dt_node *rng;
+ int rc;
+
+ gcid = dt_get_chip_id(node);
+ pb_base = dt_get_address(node, 0, NULL);
+
+ if (dt_node_is_compatible(node, "ibm,power7-nx")) {
+ xbar = pb_base + NX_P7_RNG_BAR;
+ xcfg = pb_base + NX_P7_RNG_CFG;
+ } else if (dt_node_is_compatible(node, "ibm,power8-nx")) {
+ xbar = pb_base + NX_P8_RNG_BAR;
+ xcfg = pb_base + NX_P8_RNG_CFG;
+ } else {
+ prerror("NX%d: Unknown NX type!\n", gcid);
+ return;
+ }
+
+ rc = xscom_read(gcid, xbar, &bar); /* Get RNG BAR */
+ if (rc)
+ return; /* Hope xscom always prints error message */
+
+ rc = xscom_read(gcid, xcfg, &cfg); /* Get RNG CFG */
+ if (rc)
+ return;
+
+ /*
+ * We use the P8 BAR constants. The layout of the BAR is the
+ * same, with more bits at the top of P8 which are hard wired to
+ * 0 on P7. We also mask in-place rather than using GETFIELD
+ * for the base address as we happen to *know* that it's properly
+ * aligned in the register.
+ *
+ * FIXME? Always assusme BAR gets a valid address from FSP
+ */
+ rng_addr = bar & NX_P8_RNG_BAR_ADDR;
+ len = GETFIELD(NX_P8_RNG_BAR_SIZE, bar);
+ if (len > 4) {
+ prerror("NX%d: Corrupted bar size %lld\n", gcid, len);
+ return;
+ }
+ rng_len = (u64[]){ 0x1000, /* 4K */
+ 0x10000, /* 64K */
+ 0x400000000, /* 16G*/
+ 0x100000, /* 1M */
+ 0x1000000 /* 16M */} [len];
+
+
+ prlog(PR_INFO, "NX%d: RNG BAR set to 0x%016llx..0x%016llx\n",
+ gcid, rng_addr, rng_addr + rng_len - 1);
+
+ /* RNG must be enabled before MMIO is enabled */
+ rc = xscom_write(gcid, xcfg, cfg | NX_P8_RNG_CFG_ENABLE);
+ if (rc)
+ return;
+
+ /* The BAR needs to be enabled too */
+ rc = xscom_write(gcid, xbar, bar | NX_P8_RNG_BAR_ENABLE);
+ if (rc)
+ return;
+ rng = dt_new_addr(dt_root, "hwrng", rng_addr);
+ if (!rng)
+ return;
+
+ dt_add_property_strings(rng, "compatible", "ibm,power-rng");
+ dt_add_property_cells(rng, "reg", hi32(rng_addr), lo32(rng_addr),
+ hi32(rng_len), lo32(rng_len));
+ dt_add_property_cells(rng, "ibm,chip-id", gcid);
+}
OpenPOWER on IntegriCloud