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
;
31 struct resource w1_res
;
34 offset
= NODE_OFFSET(nasid
);
36 wd
= kzalloc(sizeof(*wd
), GFP_KERNEL
);
40 snprintf(wd
->dev_id
, sizeof(wd
->dev_id
), "bridge-%012lx",
41 offset
+ (widget
<< SWIN_SIZE_BITS
));
43 memset(&w1_res
, 0, sizeof(w1_res
));
44 w1_res
.start
= offset
+ (widget
<< SWIN_SIZE_BITS
) +
45 offsetof(struct bridge_regs
, b_nic
);
46 w1_res
.end
= w1_res
.start
+ 3;
47 w1_res
.flags
= IORESOURCE_MEM
;
49 pdev
= platform_device_alloc("sgi_w1", PLATFORM_DEVID_AUTO
);
54 platform_device_add_resources(pdev
, &w1_res
, 1);
55 platform_device_add_data(pdev
, wd
, sizeof(*wd
));
56 platform_device_add(pdev
);
58 bd
= kzalloc(sizeof(*bd
), GFP_KERNEL
);
61 pdev
= platform_device_alloc("xtalk-bridge", PLATFORM_DEVID_AUTO
);
68 bd
->bridge_addr
= RAW_NODE_SWIN_BASE(nasid
, widget
);
69 bd
->intr_addr
= BIT_ULL(47) + 0x01800000 + PI_INT_PEND_MOD
;
71 bd
->masterwid
= masterwid
;
73 bd
->mem
.name
= "Bridge PCI MEM";
74 bd
->mem
.start
= offset
+ (widget
<< SWIN_SIZE_BITS
) + BRIDGE_DEVIO0
;
75 bd
->mem
.end
= offset
+ (widget
<< SWIN_SIZE_BITS
) + SWIN_SIZE
- 1;
76 bd
->mem
.flags
= IORESOURCE_MEM
;
77 bd
->mem_offset
= offset
;
79 bd
->io
.name
= "Bridge PCI IO";
80 bd
->io
.start
= offset
+ (widget
<< SWIN_SIZE_BITS
) + BRIDGE_DEVIO0
;
81 bd
->io
.end
= offset
+ (widget
<< SWIN_SIZE_BITS
) + SWIN_SIZE
- 1;
82 bd
->io
.flags
= IORESOURCE_IO
;
83 bd
->io_offset
= offset
;
85 platform_device_add_data(pdev
, bd
, sizeof(*bd
));
86 platform_device_add(pdev
);
87 pr_info("xtalk:n%d/%x bridge widget\n", nasid
, widget
);
91 pr_warn("xtalk:n%d/%x bridge create out of memory\n", nasid
, widget
);
94 static int probe_one_port(nasid_t nasid
, int widget
, int masterwid
)
96 widgetreg_t widget_id
;
97 xwidget_part_num_t partnum
;
99 widget_id
= *(volatile widgetreg_t
*)
100 (RAW_NODE_SWIN_BASE(nasid
, widget
) + WIDGET_ID
);
101 partnum
= XWIDGET_PART_NUM(widget_id
);
104 case BRIDGE_WIDGET_PART_NUM
:
105 case XBRIDGE_WIDGET_PART_NUM
:
106 bridge_platform_create(nasid
, widget
, masterwid
);
109 pr_info("xtalk:n%d/%d unknown widget (0x%x)\n",
110 nasid
, widget
, partnum
);
117 static int xbow_probe(nasid_t nasid
)
121 unsigned masterwid
, i
;
124 * found xbow, so may have multiple bridges
127 brd
= find_lboard((lboard_t
*)KL_CONFIG_INFO(nasid
), KLTYPE_MIDPLANE8
);
131 xbow_p
= (klxbow_t
*)find_component(brd
, NULL
, KLSTRUCT_XBOW
);
136 * Okay, here's a xbow. Let's arbitrate and find
137 * out if we should initialize it. Set enabled
138 * hub connected at highest or lowest widget as
142 i
= HUB_WIDGET_ID_MAX
+ 1;
145 } while ((!XBOW_PORT_TYPE_HUB(xbow_p
, i
)) ||
146 (!XBOW_PORT_IS_ENABLED(xbow_p
, i
)));
148 i
= HUB_WIDGET_ID_MIN
- 1;
151 } while ((!XBOW_PORT_TYPE_HUB(xbow_p
, i
)) ||
152 (!XBOW_PORT_IS_ENABLED(xbow_p
, i
)));
156 if (nasid
!= XBOW_PORT_NASID(xbow_p
, i
))
159 for (i
= HUB_WIDGET_ID_MIN
; i
<= HUB_WIDGET_ID_MAX
; i
++) {
160 if (XBOW_PORT_IS_ENABLED(xbow_p
, i
) &&
161 XBOW_PORT_TYPE_IO(xbow_p
, i
))
162 probe_one_port(nasid
, i
, masterwid
);
168 static void xtalk_probe_node(nasid_t nasid
)
171 xwidget_part_num_t partnum
;
172 widgetreg_t widget_id
;
174 hubreg
= REMOTE_HUB_L(nasid
, IIO_LLP_CSR
);
176 /* check whether the link is up */
177 if (!(hubreg
& IIO_LLP_CSR_IS_UP
))
180 widget_id
= *(volatile widgetreg_t
*)
181 (RAW_NODE_SWIN_BASE(nasid
, 0x0) + WIDGET_ID
);
182 partnum
= XWIDGET_PART_NUM(widget_id
);
185 case BRIDGE_WIDGET_PART_NUM
:
186 bridge_platform_create(nasid
, 0x8, 0xa);
188 case XBOW_WIDGET_PART_NUM
:
189 case XXBOW_WIDGET_PART_NUM
:
190 pr_info("xtalk:n%d/0 xbow widget\n", nasid
);
194 pr_info("xtalk:n%d/0 unknown widget (0x%x)\n", nasid
, partnum
);
199 static int __init
xtalk_init(void)
203 for_each_online_node(nasid
)
204 xtalk_probe_node(nasid
);
208 arch_initcall(xtalk_init
);