Skip to content

Commit fb702b9

Browse files
arch/tile: Enable more sophisticated IRQ model for 32-bit chips.
This model is based on the on-chip interrupt model used by the TILE-Gx next-generation hardware, and interacts much more cleanly with the Linux generic IRQ layer. The change includes modifications to the Tilera hypervisor, which are reflected in the hypervisor headers in arch/tile/include/arch/. Signed-off-by: Chris Metcalf <cmetcalf@tilera.com> Acked-by: Thomas Gleixner <tglx@linutronix.de>
1 parent de5d9bf commit fb702b9

9 files changed

Lines changed: 435 additions & 154 deletions

File tree

‎arch/tile/include/arch/chip_tile64.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,5 +248,8 @@
248248
/** Does the chip support rev1 DMA packets? */
249249
#define CHIP_HAS_REV1_DMA_PACKETS() 0
250250

251+
/** Does the chip have an IPI shim? */
252+
#define CHIP_HAS_IPI() 0
253+
251254
#endif /* !__OPEN_SOURCE__ */
252255
#endif /* __ARCH_CHIP_H__ */

‎arch/tile/include/arch/chip_tilepro.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,5 +248,8 @@
248248
/** Does the chip support rev1 DMA packets? */
249249
#define CHIP_HAS_REV1_DMA_PACKETS() 1
250250

251+
/** Does the chip have an IPI shim? */
252+
#define CHIP_HAS_IPI() 0
253+
251254
#endif /* !__OPEN_SOURCE__ */
252255
#endif /* __ARCH_CHIP_H__ */

‎arch/tile/include/asm/irq.h‎

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,65 @@
2323
/* IRQ numbers used for linux IPIs. */
2424
#define IRQ_RESCHEDULE 1
2525

26-
/* The HV interrupt state object. */
27-
DECLARE_PER_CPU(HV_IntrState, dev_intr_state);
28-
2926
void ack_bad_irq(unsigned int irq);
3027

3128
/*
32-
* Paravirtualized drivers should call this when their init calls
33-
* discover a valid HV IRQ.
29+
* Different ways of handling interrupts. Tile interrupts are always
30+
* per-cpu; there is no global interrupt controller to implement
31+
* enable/disable. Most onboard devices can send their interrupts to
32+
* many tiles at the same time, and Tile-specific drivers know how to
33+
* deal with this.
34+
*
35+
* However, generic devices (usually PCIE based, sometimes GPIO)
36+
* expect that interrupts will fire on a single core at a time and
37+
* that the irq can be enabled or disabled from any core at any time.
38+
* We implement this by directing such interrupts to a single core.
39+
*
40+
* One added wrinkle is that PCI interrupts can be either
41+
* hardware-cleared (legacy interrupts) or software cleared (MSI).
42+
* Other generic device systems (GPIO) are always software-cleared.
43+
*
44+
* The enums below are used by drivers for onboard devices, including
45+
* the internals of PCI root complex and GPIO. They allow the driver
46+
* to tell the generic irq code what kind of interrupt is mapped to a
47+
* particular IRQ number.
48+
*/
49+
enum {
50+
/* per-cpu interrupt; use enable/disable_percpu_irq() to mask */
51+
TILE_IRQ_PERCPU,
52+
/* global interrupt, hardware responsible for clearing. */
53+
TILE_IRQ_HW_CLEAR,
54+
/* global interrupt, software responsible for clearing. */
55+
TILE_IRQ_SW_CLEAR,
56+
};
57+
58+
59+
/*
60+
* Paravirtualized drivers should call this when they dynamically
61+
* allocate a new IRQ or discover an IRQ that was pre-allocated by the
62+
* hypervisor for use with their particular device. This gives the
63+
* IRQ subsystem an opportunity to do interrupt-type-specific
64+
* initialization.
65+
*
66+
* ISSUE: We should modify this API so that registering anything
67+
* except percpu interrupts also requires providing callback methods
68+
* for enabling and disabling the interrupt. This would allow the
69+
* generic IRQ code to proxy enable/disable_irq() calls back into the
70+
* PCI subsystem, which in turn could enable or disable the interrupt
71+
* at the PCI shim.
3472
*/
35-
void tile_irq_activate(unsigned int irq);
73+
void tile_irq_activate(unsigned int irq, int tile_irq_type);
74+
75+
/*
76+
* For onboard, non-PCI (e.g. TILE_IRQ_PERCPU) devices, drivers know
77+
* how to use enable/disable_percpu_irq() to manage interrupts on each
78+
* core. We can't use the generic enable/disable_irq() because they
79+
* use a single reference count per irq, rather than per cpu per irq.
80+
*/
81+
void enable_percpu_irq(unsigned int irq);
82+
void disable_percpu_irq(unsigned int irq);
83+
84+
85+
void setup_irq_regs(void);
3686

3787
#endif /* _ASM_TILE_IRQ_H */

‎arch/tile/include/asm/smp.h‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <asm/processor.h>
2121
#include <linux/cpumask.h>
2222
#include <linux/irqreturn.h>
23+
#include <hv/hypervisor.h>
2324

2425
/* Set up this tile to support receiving hypervisor messages */
2526
void init_messaging(void);
@@ -39,9 +40,6 @@ void send_IPI_single(int dest, int tag);
3940
/* Process an IPI message */
4041
void evaluate_message(int tag);
4142

42-
/* Process an IRQ_RESCHEDULE IPI. */
43-
irqreturn_t handle_reschedule_ipi(int irq, void *token);
44-
4543
/* Boot a secondary cpu */
4644
void online_secondary(void);
4745

@@ -56,6 +54,20 @@ extern HV_Topology smp_topology;
5654
#define smp_height (smp_topology.height)
5755
#define smp_width (smp_topology.width)
5856

57+
/* Convenience functions for converting cpu <-> coords. */
58+
static inline int cpu_x(int cpu)
59+
{
60+
return cpu % smp_width;
61+
}
62+
static inline int cpu_y(int cpu)
63+
{
64+
return cpu / smp_width;
65+
}
66+
static inline int xy_to_cpu(int x, int y)
67+
{
68+
return y * smp_width + x;
69+
}
70+
5971
/* Hypervisor message tags sent via the tile send_IPI*() routines. */
6072
#define MSG_TAG_START_CPU 1
6173
#define MSG_TAG_STOP_CPU 2
@@ -85,6 +97,9 @@ void print_disabled_cpus(void);
8597
#define smp_master_cpu 0
8698
#define smp_height 1
8799
#define smp_width 1
100+
#define cpu_x(cpu) 0
101+
#define cpu_y(cpu) 0
102+
#define xy_to_cpu(x, y) 0
88103

89104
#endif /* !CONFIG_SMP */
90105

@@ -123,4 +138,10 @@ static inline int __cpulist_parse_crop(const char *buf, struct cpumask *dstp,
123138
return bitmap_parselist_crop(buf, cpumask_bits(dstp), nbits);
124139
}
125140

141+
/* Initialize the IPI subsystem. */
142+
void ipi_init(void);
143+
144+
/* Function for start-cpu message to cause us to jump to. */
145+
extern unsigned long start_cpu_function_addr;
146+
126147
#endif /* _ASM_TILE_SMP_H */

‎arch/tile/include/hv/hypervisor.h‎

Lines changed: 63 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,9 @@
2020
#ifndef _TILE_HV_H
2121
#define _TILE_HV_H
2222

23-
#ifdef __tile__
2423
#include <arch/chip.h>
25-
#else
26-
/* HACK: Allow use by "tools/cpack/". */
27-
#include "install/include/arch/chip.h"
28-
#endif
24+
25+
#include <hv/pagesize.h>
2926

3027
/* Linux builds want unsigned long constants, but assembler wants numbers */
3128
#ifdef __ASSEMBLER__
@@ -39,7 +36,6 @@
3936
#define __HV_SIZE_ONE 1UL
4037
#endif
4138

42-
4339
/** The log2 of the span of a level-1 page table, in bytes.
4440
*/
4541
#define HV_LOG2_L1_SPAN 32
@@ -48,21 +44,11 @@
4844
*/
4945
#define HV_L1_SPAN (__HV_SIZE_ONE << HV_LOG2_L1_SPAN)
5046

51-
/** The log2 of the size of small pages, in bytes. This value should
52-
* be verified at runtime by calling hv_sysconf(HV_SYSCONF_PAGE_SIZE_SMALL).
53-
*/
54-
#define HV_LOG2_PAGE_SIZE_SMALL 16
55-
5647
/** The size of small pages, in bytes. This value should be verified
5748
* at runtime by calling hv_sysconf(HV_SYSCONF_PAGE_SIZE_SMALL).
5849
*/
5950
#define HV_PAGE_SIZE_SMALL (__HV_SIZE_ONE << HV_LOG2_PAGE_SIZE_SMALL)
6051

61-
/** The log2 of the size of large pages, in bytes. This value should be
62-
* verified at runtime by calling hv_sysconf(HV_SYSCONF_PAGE_SIZE_LARGE).
63-
*/
64-
#define HV_LOG2_PAGE_SIZE_LARGE 24
65-
6652
/** The size of large pages, in bytes. This value should be verified
6753
* at runtime by calling hv_sysconf(HV_SYSCONF_PAGE_SIZE_LARGE).
6854
*/
@@ -93,7 +79,7 @@
9379
#define HV_DISPATCH_ENTRY_SIZE 32
9480

9581
/** Version of the hypervisor interface defined by this file */
96-
#define _HV_VERSION 10
82+
#define _HV_VERSION 11
9783

9884
/* Index into hypervisor interface dispatch code blocks.
9985
*
@@ -253,29 +239,41 @@
253239
/** hv_set_command_line */
254240
#define HV_DISPATCH_SET_COMMAND_LINE 47
255241

256-
/** hv_dev_register_intr_state */
257-
#define HV_DISPATCH_DEV_REGISTER_INTR_STATE 48
242+
#if !CHIP_HAS_IPI()
243+
244+
/** hv_clear_intr */
245+
#define HV_DISPATCH_CLEAR_INTR 48
258246

259247
/** hv_enable_intr */
260248
#define HV_DISPATCH_ENABLE_INTR 49
261249

262250
/** hv_disable_intr */
263251
#define HV_DISPATCH_DISABLE_INTR 50
264252

253+
/** hv_raise_intr */
254+
#define HV_DISPATCH_RAISE_INTR 51
255+
265256
/** hv_trigger_ipi */
266-
#define HV_DISPATCH_TRIGGER_IPI 51
257+
#define HV_DISPATCH_TRIGGER_IPI 52
258+
259+
#endif /* !CHIP_HAS_IPI() */
267260

268261
/** hv_store_mapping */
269-
#define HV_DISPATCH_STORE_MAPPING 52
262+
#define HV_DISPATCH_STORE_MAPPING 53
270263

271264
/** hv_inquire_realpa */
272-
#define HV_DISPATCH_INQUIRE_REALPA 53
265+
#define HV_DISPATCH_INQUIRE_REALPA 54
273266

274267
/** hv_flush_all */
275-
#define HV_DISPATCH_FLUSH_ALL 54
268+
#define HV_DISPATCH_FLUSH_ALL 55
269+
270+
#if CHIP_HAS_IPI()
271+
/** hv_get_ipi_pte */
272+
#define HV_DISPATCH_GET_IPI_PTE 56
273+
#endif
276274

277275
/** One more than the largest dispatch value */
278-
#define _HV_DISPATCH_END 55
276+
#define _HV_DISPATCH_END 57
279277

280278

281279
#ifndef __ASSEMBLER__
@@ -484,21 +482,6 @@ typedef enum {
484482
*/
485483
int hv_confstr(HV_ConfstrQuery query, HV_VirtAddr buf, int len);
486484

487-
/** State object used to enable and disable one-shot and level-sensitive
488-
* interrupts. */
489-
typedef struct
490-
{
491-
#if CHIP_VA_WIDTH() > 32
492-
__hv64 opaque[2]; /**< No user-serviceable parts inside */
493-
#else
494-
__hv32 opaque[2]; /**< No user-serviceable parts inside */
495-
#endif
496-
}
497-
HV_IntrState;
498-
499-
/** A set of interrupts. */
500-
typedef __hv32 HV_IntrMask;
501-
502485
/** Tile coordinate */
503486
typedef struct
504487
{
@@ -509,34 +492,51 @@ typedef struct
509492
int y;
510493
} HV_Coord;
511494

495+
496+
#if CHIP_HAS_IPI()
497+
498+
/** Get the PTE for sending an IPI to a particular tile.
499+
*
500+
* @param tile Tile which will receive the IPI.
501+
* @param pl Indicates which IPI registers: 0 = IPI_0, 1 = IPI_1.
502+
* @param pte Filled with resulting PTE.
503+
* @result Zero if no error, non-zero for invalid parameters.
504+
*/
505+
int hv_get_ipi_pte(HV_Coord tile, int pl, HV_PTE* pte);
506+
507+
#else /* !CHIP_HAS_IPI() */
508+
509+
/** A set of interrupts. */
510+
typedef __hv32 HV_IntrMask;
511+
512512
/** The low interrupt numbers are reserved for use by the client in
513513
* delivering IPIs. Any interrupt numbers higher than this value are
514514
* reserved for use by HV device drivers. */
515515
#define HV_MAX_IPI_INTERRUPT 7
516516

517-
/** Register an interrupt state object. This object is used to enable and
518-
* disable one-shot and level-sensitive interrupts. Once the state is
519-
* registered, the client must not read or write the state object; doing
520-
* so will cause undefined results.
517+
/** Enable a set of device interrupts.
521518
*
522-
* @param intr_state Pointer to interrupt state object.
523-
* @return HV_OK on success, or a hypervisor error code.
519+
* @param enab_mask Bitmap of interrupts to enable.
524520
*/
525-
HV_Errno hv_dev_register_intr_state(HV_IntrState* intr_state);
521+
void hv_enable_intr(HV_IntrMask enab_mask);
526522

527-
/** Enable a set of one-shot and level-sensitive interrupts.
523+
/** Disable a set of device interrupts.
528524
*
529-
* @param intr_state Pointer to interrupt state object.
530-
* @param enab_mask Bitmap of interrupts to enable.
525+
* @param disab_mask Bitmap of interrupts to disable.
531526
*/
532-
void hv_enable_intr(HV_IntrState* intr_state, HV_IntrMask enab_mask);
527+
void hv_disable_intr(HV_IntrMask disab_mask);
533528

534-
/** Disable a set of one-shot and level-sensitive interrupts.
529+
/** Clear a set of device interrupts.
535530
*
536-
* @param intr_state Pointer to interrupt state object.
537-
* @param disab_mask Bitmap of interrupts to disable.
531+
* @param clear_mask Bitmap of interrupts to clear.
538532
*/
539-
void hv_disable_intr(HV_IntrState* intr_state, HV_IntrMask disab_mask);
533+
void hv_clear_intr(HV_IntrMask clear_mask);
534+
535+
/** Assert a set of device interrupts.
536+
*
537+
* @param assert_mask Bitmap of interrupts to clear.
538+
*/
539+
void hv_assert_intr(HV_IntrMask assert_mask);
540540

541541
/** Trigger a one-shot interrupt on some tile
542542
*
@@ -547,6 +547,8 @@ void hv_disable_intr(HV_IntrState* intr_state, HV_IntrMask disab_mask);
547547
*/
548548
HV_Errno hv_trigger_ipi(HV_Coord tile, int interrupt);
549549

550+
#endif // !CHIP_HAS_IPI()
551+
550552
/** Store memory mapping in debug memory so that external debugger can read it.
551553
* A maximum of 16 entries can be stored.
552554
*
@@ -1010,6 +1012,13 @@ int hv_console_write(HV_VirtAddr bytes, int len);
10101012
* it will return to the code which was interrupted by the INTCTRL_1
10111013
* interrupt.
10121014
*
1015+
* Under some circumstances, the firing of INTCTRL_1 can race with
1016+
* the lowering of a device interrupt. In such a case, the
1017+
* hv_downcall_dispatch service may issue an iret instruction instead
1018+
* of entering one of the client's actual downcall-handling interrupt
1019+
* vectors. This will return execution to the location that was
1020+
* interrupted by INTCTRL_1.
1021+
*
10131022
* Any saving of registers should be done by the actual handling
10141023
* vectors; no registers should be changed by the INTCTRL_1 handler.
10151024
* In particular, the client should not use a jal instruction to invoke

‎arch/tile/include/hv/pagesize.h‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright 2010 Tilera Corporation. All Rights Reserved.
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License
6+
* as published by the Free Software Foundation, version 2.
7+
*
8+
* This program is distributed in the hope that it will be useful, but
9+
* WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11+
* NON INFRINGEMENT. See the GNU General Public License for
12+
* more details.
13+
*/
14+
15+
/**
16+
* @file pagesize.h
17+
*/
18+
19+
#ifndef _HV_PAGESIZE_H
20+
#define _HV_PAGESIZE_H
21+
22+
/** The log2 of the size of small pages, in bytes. This value should
23+
* be verified at runtime by calling hv_sysconf(HV_SYSCONF_PAGE_SIZE_SMALL).
24+
*/
25+
#define HV_LOG2_PAGE_SIZE_SMALL 16
26+
27+
/** The log2 of the size of large pages, in bytes. This value should be
28+
* verified at runtime by calling hv_sysconf(HV_SYSCONF_PAGE_SIZE_LARGE).
29+
*/
30+
#define HV_LOG2_PAGE_SIZE_LARGE 24
31+
32+
#endif /* _HV_PAGESIZE_H */

0 commit comments

Comments
 (0)