1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 1999, 2000 Ralf Baechle (ralf@gnu.org)
4 * Copyright (C) 1999, 2000 Silcon Graphics, Inc.
5 * Copyright (C) 2004 Christoph Hellwig.
7 * Generic XTALK initialization code
10 #include <linux/kernel.h>
11 #include <linux/smp.h>
12 #include <linux/platform_device.h>
13 #include <linux/platform_data/sgi-w1.h>
14 #include <linux/platform_data/xtalk-bridge.h>
15 #include <asm/sn/addrs.h>
16 #include <asm/sn/types.h>
17 #include <asm/sn/klconfig.h>
18 #include <asm/pci/bridge.h>
19 #include <asm/xtalk/xtalk.h>
22 #define XBOW_WIDGET_PART_NUM 0x0
23 #define XXBOW_WIDGET_PART_NUM 0xd000 /* Xbow in Xbridge */
24 #define BASE_XBOW_PORT 8 /* Lowest external port */
26 static void bridge_platform_create(nasid_t nasid
, int widget
, int masterwid
)
28 struct xtalk_bridge_platform_data
*bd
;
29 struct sgi_w1_platform_data
*wd
;
30 struct platform_device
*pdev_wd
;
31 struct platform_device
*pdev_bd
;
32 struct resource w1_res
;
35 offset
= NODE_OFFSET(nasid
);
37 wd
= kzalloc(sizeof(*wd
), GFP_KERNEL
);
39 pr_warn("xtalk:n%d/%x bridge create out of memory\n", nasid
, widget
);
43 snprintf(wd
->dev_id
, sizeof(wd
->dev_id
), "bridge-%012lx",
44 offset
+ (widget
<< SWIN_SIZE_BITS
));
46 memset(&w1_res
, 0, sizeof(w1_res
));
47 w1_res
.start
= offset
+ (widget
<< SWIN_SIZE_BITS
) +
48 offsetof(struct bridge_regs
, b_nic
);
49 w1_res
.end
= w1_res
.start
+ 3;
50 w1_res
.flags
= IORESOURCE_MEM
;
52 pdev_wd
= platform_device_alloc("sgi_w1", PLATFORM_DEVID_AUTO
);
54 pr_warn("xtalk:n%d/%x bridge create out of memory\n", nasid
, widget
);
57 if (platform_device_add_resources(pdev_wd
, &w1_res
, 1)) {
58 pr_warn("xtalk:n%d/%x bridge failed to add platform resources.\n", nasid
, widget
);
61 if (platform_device_add_data(pdev_wd
, wd
, sizeof(*wd
))) {
62 pr_warn("xtalk:n%d/%x bridge failed to add platform data.\n", nasid
, widget
);
65 if (platform_device_add(pdev_wd
)) {
66 pr_warn("xtalk:n%d/%x bridge failed to add platform device.\n", nasid
, widget
);
69 /* platform_device_add_data() duplicates the data */
72 bd
= kzalloc(sizeof(*bd
), GFP_KERNEL
);
74 pr_warn("xtalk:n%d/%x bridge create out of memory\n", nasid
, widget
);
75 goto err_unregister_pdev_wd
;
77 pdev_bd
= platform_device_alloc("xtalk-bridge", PLATFORM_DEVID_AUTO
);
79 pr_warn("xtalk:n%d/%x bridge create out of memory\n", nasid
, widget
);
84 bd
->bridge_addr
= RAW_NODE_SWIN_BASE(nasid
, widget
);
85 bd
->intr_addr
= BIT_ULL(47) + 0x01800000 + PI_INT_PEND_MOD
;
87 bd
->masterwid
= masterwid
;
89 bd
->mem
.name
= "Bridge PCI MEM";
90 bd
->mem
.start
= offset
+ (widget
<< SWIN_SIZE_BITS
) + BRIDGE_DEVIO0
;
91 bd
->mem
.end
= offset
+ (widget
<< SWIN_SIZE_BITS
) + SWIN_SIZE
- 1;
92 bd
->mem
.flags
= IORESOURCE_MEM
;
93 bd
->mem_offset
= offset
;
95 bd
->io
.name
= "Bridge PCI IO";
96 bd
->io
.start
= offset
+ (widget
<< SWIN_SIZE_BITS
) + BRIDGE_DEVIO0
;
97 bd
->io
.end
= offset
+ (widget
<< SWIN_SIZE_BITS
) + SWIN_SIZE
- 1;
98 bd
->io
.flags
= IORESOURCE_IO
;
99 bd
->io_offset
= offset
;
101 if (platform_device_add_data(pdev_bd
, bd
, sizeof(*bd
))) {
102 pr_warn("xtalk:n%d/%x bridge failed to add platform data.\n", nasid
, widget
);
103 goto err_put_pdev_bd
;
105 if (platform_device_add(pdev_bd
)) {
106 pr_warn("xtalk:n%d/%x bridge failed to add platform device.\n", nasid
, widget
);
107 goto err_put_pdev_bd
;
109 /* platform_device_add_data() duplicates the data */
111 pr_info("xtalk:n%d/%x bridge widget\n", nasid
, widget
);
115 platform_device_put(pdev_bd
);
118 err_unregister_pdev_wd
:
119 platform_device_unregister(pdev_wd
);
122 platform_device_put(pdev_wd
);
128 static int probe_one_port(nasid_t nasid
, int widget
, int masterwid
)
130 widgetreg_t widget_id
;
131 xwidget_part_num_t partnum
;
133 widget_id
= *(volatile widgetreg_t
*)
134 (RAW_NODE_SWIN_BASE(nasid
, widget
) + WIDGET_ID
);
135 partnum
= XWIDGET_PART_NUM(widget_id
);
138 case BRIDGE_WIDGET_PART_NUM
:
139 case XBRIDGE_WIDGET_PART_NUM
:
140 bridge_platform_create(nasid
, widget
, masterwid
);
143 pr_info("xtalk:n%d/%d unknown widget (0x%x)\n",
144 nasid
, widget
, partnum
);
151 static int xbow_probe(nasid_t nasid
)
155 unsigned masterwid
, i
;
158 * found xbow, so may have multiple bridges
161 brd
= find_lboard((lboard_t
*)KL_CONFIG_INFO(nasid
), KLTYPE_MIDPLANE8
);
165 xbow_p
= (klxbow_t
*)find_component(brd
, NULL
, KLSTRUCT_XBOW
);
170 * Okay, here's a xbow. Let's arbitrate and find
171 * out if we should initialize it. Set enabled
172 * hub connected at highest or lowest widget as
176 i
= HUB_WIDGET_ID_MAX
+ 1;
179 } while ((!XBOW_PORT_TYPE_HUB(xbow_p
, i
)) ||
180 (!XBOW_PORT_IS_ENABLED(xbow_p
, i
)));
182 i
= HUB_WIDGET_ID_MIN
- 1;
185 } while ((!XBOW_PORT_TYPE_HUB(xbow_p
, i
)) ||
186 (!XBOW_PORT_IS_ENABLED(xbow_p
, i
)));
190 if (nasid
!= XBOW_PORT_NASID(xbow_p
, i
))
193 for (i
= HUB_WIDGET_ID_MIN
; i
<= HUB_WIDGET_ID_MAX
; i
++) {
194 if (XBOW_PORT_IS_ENABLED(xbow_p
, i
) &&
195 XBOW_PORT_TYPE_IO(xbow_p
, i
))
196 probe_one_port(nasid
, i
, masterwid
);
202 static void xtalk_probe_node(nasid_t nasid
)
205 xwidget_part_num_t partnum
;
206 widgetreg_t widget_id
;
208 hubreg
= REMOTE_HUB_L(nasid
, IIO_LLP_CSR
);
210 /* check whether the link is up */
211 if (!(hubreg
& IIO_LLP_CSR_IS_UP
))
214 widget_id
= *(volatile widgetreg_t
*)
215 (RAW_NODE_SWIN_BASE(nasid
, 0x0) + WIDGET_ID
);
216 partnum
= XWIDGET_PART_NUM(widget_id
);
219 case BRIDGE_WIDGET_PART_NUM
:
220 bridge_platform_create(nasid
, 0x8, 0xa);
222 case XBOW_WIDGET_PART_NUM
:
223 case XXBOW_WIDGET_PART_NUM
:
224 pr_info("xtalk:n%d/0 xbow widget\n", nasid
);
228 pr_info("xtalk:n%d/0 unknown widget (0x%x)\n", nasid
, partnum
);
233 static int __init
xtalk_init(void)
237 for_each_online_node(nasid
)
238 xtalk_probe_node(nasid
);
242 arch_initcall(xtalk_init
);