From: Ian Campbell <Ian.Campbell@citrix.com>
To: Thomas Leonard <talex5@gmail.com>
Cc: Dave.Scott@eu.citrix.com, anil@recoil.org,
stefano.stabellini@eu.citrix.com, samuel.thibault@ens-lyon.org,
xen-devel@lists.xenproject.org
Subject: Re: [PATCH ARM v8 2/4] mini-os: arm: interrupt controller
Date: Tue, 21 Oct 2014 12:00:18 +0100 [thread overview]
Message-ID: <1413889218.23337.24.camel@citrix.com> (raw)
In-Reply-To: <1412328051-20015-3-git-send-email-talex5@gmail.com>
On Fri, 2014-10-03 at 10:20 +0100, Thomas Leonard wrote:
> +static inline uint32_t REG_READ32(volatile uint32_t *addr)
> +{
> + uint32_t value;
> + __asm__ __volatile__("ldr %0, [%1]":"=&r"(value):"r"(addr));
> + rmb();
I'm not 100% convinced that you need this rmb().
> + return value;
> +}
> +
> +static inline void REG_WRITE32(volatile uint32_t *addr, unsigned int value)
> +{
> + __asm__ __volatile__("str %0, [%1]"::"r"(value), "r"(addr));
> + wmb();
> +}
> +
> +static void gic_set_priority(struct gic *gic, int irq_number, unsigned char priority)
> +{
> + uint32_t value;
> + uint32_t *addr = REG(gicd(gic, GICD_IPRIORITYR)) + (irq_number >> 2);
> + value = REG_READ32(addr);
> + value &= ~(0xff << (8 * (irq_number & 0x3))); // clear old priority
> + value |= priority << (8 * (irq_number & 0x3)); // set new priority
> + REG_WRITE32(addr, value);
I believe the IPRIORITYR registers are byte addressable, so you can just
do a strb of the new value without needing to read-modify-write.
> +static void gic_route_interrupt(struct gic *gic, int irq_number, unsigned char cpu_set)
> +{
> + uint32_t value;
> + uint32_t *addr = REG(gicd(gic, GICD_ITARGETSR)) + (irq_number >> 2);
> + value = REG_READ32(addr);
> + value &= ~(0xff << (8 * (irq_number & 0x3))); // clear old target
> + value |= cpu_set << (8 * (irq_number & 0x3)); // set new target
> + REG_WRITE32(addr, value);
Same for ITARGETSR.
> +/* Note: not thread safe (but we only support one CPU for now anyway) */
> +static void gic_enable_interrupt(struct gic *gic, int irq_number,
> + unsigned char cpu_set, unsigned char level_sensitive, unsigned char ppi)
> +{
> + void *set_enable_reg;
> + void *cfg_reg;
> +
> + // set priority
> + gic_set_priority(gic, irq_number, 0x0);
> +
> + // set target cpus for this interrupt
> + gic_route_interrupt(gic, irq_number, cpu_set);
> +
> + // set level/edge triggered
> + cfg_reg = (void *)gicd(gic, GICD_ICFGR);
> + if (level_sensitive) {
> + clear_bit_non_atomic((irq_number * 2) + 1, cfg_reg);
> + } else {
> + set_bit_non_atomic((irq_number * 2) + 1, cfg_reg);
> + }
> + if (ppi)
missing else? Or should be folded in above as level_sensitive||ppi
> + clear_bit_non_atomic((irq_number * 2), cfg_reg);
> +
> + wmb();
> +
> + // enable forwarding interrupt from distributor to cpu interface
> + set_enable_reg = (void *)gicd(gic, GICD_ISENABLER);
> + set_bit_non_atomic(irq_number, set_enable_reg);
I think the semantics of ISENABLER are that you write the bit you want
to enable as 1 and that zeroes are ignored. IOW you can just use a
normal write with the correct shift.
A clear is done via the separate ICENABLER, not by writing 0 to this
register.
> +//FIXME Get event_irq from dt
> +#define EVENTS_IRQ 31
> +#define VIRTUALTIMER_IRQ 27
> +
> +static void gic_handler(void) {
> + unsigned int irq = gic_readiar(&gic);
> +
> + DEBUG("IRQ received : %i\n", irq);
> + switch(irq) {
> + case EVENTS_IRQ:
> + do_hypervisor_callback(NULL);
> + break;
> + case VIRTUALTIMER_IRQ:
> + /* We need to get this event to wake us up from block_domain,
> + * but we don't need to do anything special with it. */
> + break;
There are a few magic values in the 1020..1023 range which you may see
in practice. In particular 1023 (I think) is a spurious interrupt, which
you should silently ignore.
> + gic_enable_interrupt(&gic, EVENTS_IRQ /* interrupt number */, 0x1 /*cpu_set*/, 1 /*level_sensitive*/, 0 /* ppi */);
> + gic_enable_interrupt(&gic, VIRTUALTIMER_IRQ /* interrupt number */, 0x1 /*cpu_set*/, 1 /*level_sensitive*/, 1 /* ppi */);
BTW, ppi or not is implicit in the irq number.
> +}
next prev parent reply other threads:[~2014-10-21 11:00 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-03 9:20 [PATCH ARM v8 0/4] mini-os: initial ARM support Thomas Leonard
2014-10-03 9:20 ` [PATCH ARM v8 1/4] mini-os: arm: time Thomas Leonard
2014-10-21 10:50 ` Ian Campbell
2014-10-21 14:07 ` [PATCH incomplete] xen: arm: wallclock support (incomplete, needs work/refactoring) Ian Campbell
2014-10-26 9:51 ` [PATCH ARM v8 1/4] mini-os: arm: time Thomas Leonard
2014-10-27 10:34 ` Ian Campbell
2014-11-13 16:29 ` Thomas Leonard
2014-11-14 10:29 ` Ian Campbell
2014-11-19 20:57 ` Konrad Rzeszutek Wilk
2015-01-08 15:52 ` Ian Campbell
2015-01-08 15:58 ` Thomas Leonard
2015-01-08 16:04 ` Ian Campbell
2014-10-03 9:20 ` [PATCH ARM v8 2/4] mini-os: arm: interrupt controller Thomas Leonard
2014-10-21 11:00 ` Ian Campbell [this message]
2014-10-21 14:26 ` Julien Grall
2014-10-21 15:16 ` Ian Campbell
2014-10-21 15:22 ` Julien Grall
2014-10-21 15:35 ` Ian Campbell
2014-10-21 16:03 ` Julien Grall
2014-10-21 18:14 ` Anil Madhavapeddy
2014-10-21 19:18 ` Ian Campbell
2014-10-21 21:54 ` Samuel Thibault
2014-10-22 9:03 ` Ian Campbell
2014-10-22 13:06 ` Julien Grall
2014-10-22 13:14 ` Samuel Thibault
2014-10-28 15:15 ` Thomas Leonard
2014-10-28 15:25 ` Julien Grall
2014-10-28 15:43 ` Thomas Leonard
2014-10-28 15:51 ` Julien Grall
2014-11-14 10:22 ` Thomas Leonard
2014-11-14 11:33 ` Julien Grall
2014-11-14 11:42 ` Ian Campbell
2014-11-14 11:48 ` Julien Grall
2014-11-14 12:01 ` Ian Campbell
2014-10-03 9:20 ` [PATCH ARM v8 3/4] mini-os: arm: build system Thomas Leonard
2014-10-21 11:44 ` Ian Campbell
2014-10-21 21:50 ` Samuel Thibault
2014-10-22 9:01 ` Ian Campbell
2014-10-22 9:59 ` Samuel Thibault
2014-10-26 9:46 ` Thomas Leonard
2014-10-26 9:55 ` Samuel Thibault
2014-10-26 10:25 ` Thomas Leonard
2014-11-17 11:42 ` Thomas Leonard
2014-11-17 11:45 ` Ian Campbell
2014-11-17 11:47 ` Andrew Cooper
2014-11-17 11:47 ` Samuel Thibault
2014-10-03 9:20 ` [PATCH ARM v8 4/4] mini-os: arm: show registers, stack and exception vector on fault Thomas Leonard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1413889218.23337.24.camel@citrix.com \
--to=ian.campbell@citrix.com \
--cc=Dave.Scott@eu.citrix.com \
--cc=anil@recoil.org \
--cc=samuel.thibault@ens-lyon.org \
--cc=stefano.stabellini@eu.citrix.com \
--cc=talex5@gmail.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).