Allwinner A10 fixes
v5 cover Allwinner A10 fixes
This series introduces some fixes and missing features found while trying to run mainline Linux kernel on emulated Allwinner A10.
The changes concern interrupt handling, timer and ethernet MAC.
With these applied I'm able to boot Linux 3.14-rc2 using a NFS root:
https://gist.github.com/anonymous/3e09495652009c6b9da4
Changelog:
v5: Address comment from Peter Crosthwaite:
* use an array for timer input frequencies (patch 5)
v4: Address comments from Peter Crosthwaite:
* force argument of qemu_set_irq to 0/1
* update irq status in pit reset handler
* add properties for setting input frequencies of pit
* set pit input frequencies in cubieboard init function
v3: Address comments from Peter Crosthwaite:
* make pending register read-only (patch 2)
* inline timer context structure into timer state (patch 3)
* cleanup timer frequency initialization (patch 5)
v2: Address comments from Li Guang:
* make pic vector register read-only
* allow writing to pic pending register
Beniamino Galvani (7):
allwinner-a10-pic: set vector address when an interrupt is pending
allwinner-a10-pic: fix behaviour of pending register
allwinner-a10-pit: avoid generation of spurious interrupts
allwinner-a10-pit: use level triggered interrupts
allwinner-a10-pit: implement prescaler and source selection
allwinner-emac: set autonegotiation complete bit on link up
allwinner-emac: update irq status after writes to interrupt registers
hw/arm/cubieboard.c | 13 +++++++ hw/intc/allwinner-a10-pic.c | 22 +++++++++--- hw/net/allwinner_emac.c | 6 ++-- hw/timer/allwinner-a10-pit.c | 66 +++++++++++++++++++++++++++------- include/hw/net/allwinner_emac.h | 1 + include/hw/timer/allwinner-a10-pit.h | 9 +++++ 6 files changed, 98 insertions(+), 19 deletions(-)
Signature · 1 line
1.7.10.4
PATCH v5 1/7 allwinner-a10-pic: set vector address when an interrupt is pending
This patch implements proper updating of the vector register which should hold, according to the A10 user manual, the vector address for the interrupt currently active on the CPU IRQ input.
Interrupt priority is not implemented at the moment and thus the first pending interrupt is returned.
--- hw/intc/allwinner-a10-pic.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-)
hw/intc/allwinner-a10-pic.c +10 -4
@@ -23,11 +23,20 @@static void aw_a10_pic_update (AwA10PICState *s) {uint8_t i; -int irq =0 , fiq =0 ; +int irq =0 , fiq =0 , pending; + + s->vector =0 ;for (i =0 ; i <AW_A10_PIC_REG_NUM ; i++) { irq |= s->irq_pending[i] & ~s->mask[i]; fiq |= s->select[i] & s->irq_pending[i] & ~s->mask[i]; + +if (!s->vector) { + pending =ffs (s->irq_pending[i] & ~s->mask[i]); +if (pending) { + s->vector = (i *32 + pending -1 ) *4 ; + } + } }qemu_set_irq (s->parent_irq, !!irq);
@@ -84,9 +93,6 @@ static void aw_a10_pic_write(void *opaque, hwaddr offset, uint64_t value,uint8_t index = (offset &0xc ) /4 ;switch (offset) { -case AW_A10_PIC_VECTOR : - s->vector = value & ~0x3 ; -break ;case AW_A10_PIC_BASE_ADDR : s->base_addr = value & ~0x3 ;case AW_A10_PIC_PROTECT :
Signature · 1 line
1.7.10.4
PATCH v5 2/7 allwinner-a10-pic: fix behaviour of pending register
In reply to Beniamino GalvaniThe pending register is read-only and the value returned upon a read reflects the state of irq input pins (interrupts are level triggered). This patch implements such behaviour.
--- hw/intc/allwinner-a10-pic.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
hw/intc/allwinner-a10-pic.c +7 -1
@@ -49,6 +49,8 @@ static void aw_a10_pic_set_irq(void *opaque, int irq, int level)if (level) {set_bit (irq %32 , (void *)&s->irq_pending[irq /32 ]); + }else { +clear_bit (irq %32 , (void *)&s->irq_pending[irq /32 ]); }aw_a10_pic_update (s); }
@@ -102,7 +104,11 @@ static void aw_a10_pic_write(void *opaque, hwaddr offset, uint64_t value, s->nmi = value;break ; case AW_A10_PIC_IRQ_PENDING ... AW_A10_PIC_IRQ_PENDING + 8: - s->irq_pending[index] &= ~value; +/* +* The register is read-only; nevertheless, Linux (including +* the version originally shipped by Allwinner) pretends to +* write to the register. Just ignore it. +*/ break ; case AW_A10_PIC_FIQ_PENDING ... AW_A10_PIC_FIQ_PENDING + 8: s->fiq_pending[index] &= ~value;
Signature · 1 line
1.7.10.4
PATCH v5 3/7 allwinner-a10-pit: avoid generation of spurious interrupts
In reply to Beniamino GalvaniThe model was generating interrupts for all enabled timers after the expiration of one of them. Avoid this by passing explicitly the timer index to the callback function.
--- hw/timer/allwinner-a10-pit.c | 25 ++++++++++++++----------- include/hw/timer/allwinner-a10-pit.h | 8 ++++++++ 2 files changed, 22 insertions(+), 11 deletions(-)
hw/timer/allwinner-a10-pit.c +14 -11
@@ -193,18 +193,17 @@ static void a10_pit_reset(DeviceState *dev)static void a10_pit_timer_cb (void *opaque) { -AwA10PITState *s =AW_A10_PIT (opaque); -uint8_t i; +AwA10TimerContext *tc = opaque; +AwA10PITState *s = tc->container; +uint8_t i = tc->index; -for (i =0 ; i <AW_A10_PIT_TIMER_NR ; i++) { -if (s->control[i] &AW_A10_PIT_TIMER_EN ) { - s->irq_status |=1 << i; -if (s->control[i] &AW_A10_PIT_TIMER_MODE ) { -ptimer_stop (s->timer[i]); - s->control[i] &= ~AW_A10_PIT_TIMER_EN ; - } -qemu_irq_pulse (s->irq[i]); +if (s->control[i] &AW_A10_PIT_TIMER_EN ) { + s->irq_status |=1 << i; +if (s->control[i] &AW_A10_PIT_TIMER_MODE ) { +ptimer_stop (s->timer[i]); + s->control[i] &= ~AW_A10_PIT_TIMER_EN ; } +qemu_irq_pulse (s->irq[i]); } }
@@ -223,7 +222,11 @@ static void a10_pit_init(Object *obj)sysbus_init_mmio (sbd, &s->iomem);for (i =0 ; i <AW_A10_PIT_TIMER_NR ; i++) { - bh[i] =qemu_bh_new (a10_pit_timer_cb, s); +AwA10TimerContext *tc = &s->timer_context[i]; + + tc->container = s; + tc->index = i; + bh[i] =qemu_bh_new (a10_pit_timer_cb, tc); s->timer[i] =ptimer_init (bh[i]);ptimer_set_freq (s->timer[i],240000 ); }
include/hw/timer/allwinner-a10-pit.h +8 -0
@@ -35,12 +35,20 @@#define AW_A10_PIT_DEFAULT_CLOCK 0x4 +typedef struct AwA10PITState AwA10PITState ; + +typedef struct AwA10TimerContext { +AwA10PITState *container; +int index; +}AwA10TimerContext ; + typedef struct AwA10PITState { /*< private >*/ SysBusDevice parent_obj; /*< public >*/ qemu_irq irq[AW_A10_PIT_TIMER_NR]; ptimer_state * timer[AW_A10_PIT_TIMER_NR]; + AwA10TimerContext timer_context[AW_A10_PIT_TIMER_NR]; MemoryRegion iomem; uint32_t irq_enable;
Signature · 1 line
1.7.10.4
PATCH v5 4/7 allwinner-a10-pit: use level triggered interrupts
In reply to Beniamino GalvaniConvert the interrupt generation logic to the use of level triggered interrupts.
--- hw/timer/allwinner-a10-pit.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
hw/timer/allwinner-a10-pit.c +14 -1
@@ -19,6 +19,15 @@#include "sysemu/sysemu.h" #include "hw/timer/allwinner-a10-pit.h" +static void a10_pit_update_irq (AwA10PITState *s) +{ +int i; + +for (i =0 ; i <AW_A10_PIT_TIMER_NR ; i++) { +qemu_set_irq (s->irq[i], !!(s->irq_status & s->irq_enable & (1 << i))); + } +} +static uint64_t a10_pit_read (void *opaque,hwaddr offset,unsigned size) {AwA10PITState *s =AW_A10_PIT (opaque);
@@ -74,9 +83,11 @@ static void a10_pit_write(void *opaque, hwaddr offset, uint64_t value,switch (offset) {case AW_A10_PIT_TIMER_IRQ_EN : s->irq_enable = value; +a10_pit_update_irq (s);break ;case AW_A10_PIT_TIMER_IRQ_ST : s->irq_status &= ~value; +a10_pit_update_irq (s);break ; case AW_A10_PIT_TIMER_BASE ... AW_A10_PIT_TIMER_BASE_END: index = offset &0xf0 ;
@@ -178,6 +189,8 @@ static void a10_pit_reset(DeviceState *dev) s->irq_enable =0 ; s->irq_status =0 ; +a10_pit_update_irq (s); +for (i =0 ; i <6 ; i++) { s->control[i] =AW_A10_PIT_DEFAULT_CLOCK ; s->interval[i] =0 ;
@@ -203,7 +216,7 @@ static void a10_pit_timer_cb(void *opaque)ptimer_stop (s->timer[i]); s->control[i] &= ~AW_A10_PIT_TIMER_EN ; } -qemu_irq_pulse (s->irq[i]); +a10_pit_update_irq (s); } }
Signature · 1 line
1.7.10.4
PATCH v5 5/7 allwinner-a10-pit: implement prescaler and source selection
In reply to Beniamino GalvaniThis implements the prescaler and source fields of the timer control register. The source for each timer can be selected among 4 clock inputs whose frequencies are set through model properties.
--- hw/arm/cubieboard.c | 13 +++++++++++++ hw/timer/allwinner-a10-pit.c | 28 +++++++++++++++++++++++++++- include/hw/timer/allwinner-a10-pit.h | 1 + 3 files changed, 41 insertions(+), 1 deletion(-)
hw/arm/cubieboard.c +13 -0
@@ -43,6 +43,19 @@ static void cubieboard_init(QEMUMachineInitArgs *args)exit (1 ); } +object_property_set_int (OBJECT (&s->a10->timer),32768 ,"clk0-freq" , &err); +if (err !=NULL ) { +error_report ("Couldn't set clk0 frequency: %s" ,error_get_pretty (err)); +exit (1 ); + } + +object_property_set_int (OBJECT (&s->a10->timer),24000000 ,"clk1-freq" , + &err); +if (err !=NULL ) { +error_report ("Couldn't set clk1 frequency: %s" ,error_get_pretty (err)); +exit (1 ); + } +object_property_set_bool (OBJECT (s->a10), true,"realized" , &err);if (err !=NULL ) { error_report("Couldn't realize Allwinner A10: %s",
hw/timer/allwinner-a10-pit.c +27 -1
@@ -74,6 +74,22 @@ static uint64_t a10_pit_read(void *opaque, hwaddr offset, unsigned size)return 0 ; } +static void a10_pit_set_freq (AwA10PITState *s,int index) +{ +uint32_t prescaler, source, source_freq; + + prescaler =1 <<extract32 (s->control[index],4 ,3 ); + source =extract32 (s->control[index],2 ,2 ); + source_freq = s->clk_freq[source]; + +if (source_freq) { +ptimer_set_freq (s->timer[index], source_freq / prescaler); + }else { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: Invalid clock source %u\n" , + __func__, source); + } +} +static void a10_pit_write (void *opaque,hwaddr offset,uint64_t value,unsigned size) {
@@ -96,6 +112,7 @@ static void a10_pit_write(void *opaque, hwaddr offset, uint64_t value,switch (offset &0x0f ) {case AW_A10_PIT_TIMER_CONTROL : s->control[index] = value; +a10_pit_set_freq (s, index);if (s->control[index] &AW_A10_PIT_TIMER_RELOAD ) {ptimer_set_count (s->timer[index], s->interval[index]); }
@@ -161,6 +178,14 @@ static const MemoryRegionOps a10_pit_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; +static Property a10_pit_properties[] = { +DEFINE_PROP_UINT32 ("clk0-freq" , AwA10PITState, clk_freq[0 ],0 ), +DEFINE_PROP_UINT32 ("clk1-freq" , AwA10PITState, clk_freq[1 ],0 ), +DEFINE_PROP_UINT32 ("clk2-freq" , AwA10PITState, clk_freq[2 ],0 ), +DEFINE_PROP_UINT32 ("clk3-freq" , AwA10PITState, clk_freq[3 ],0 ), +DEFINE_PROP_END_OF_LIST (), +}; +static const VMStateDescription vmstate_a10_pit = { .name ="a10.pit" , .version_id =1 ,
@@ -196,6 +221,7 @@ static void a10_pit_reset(DeviceState *dev) s->interval[i] =0 ; s->count[i] =0 ;ptimer_stop (s->timer[i]); +a10_pit_set_freq (s, i); } s->watch_dog_mode =0 ; s->watch_dog_control =0 ;
@@ -241,7 +267,6 @@ static void a10_pit_init(Object *obj) tc->index = i; bh[i] =qemu_bh_new (a10_pit_timer_cb, tc); s->timer[i] =ptimer_init (bh[i]); -ptimer_set_freq (s->timer[i],240000 ); } }
@@ -250,6 +275,7 @@ static void a10_pit_class_init(ObjectClass *klass, void *data)DeviceClass *dc =DEVICE_CLASS (klass); dc->reset = a10_pit_reset; + dc->props = a10_pit_properties; dc->desc ="allwinner a10 timer" ; dc->vmsd = &vmstate_a10_pit; }
include/hw/timer/allwinner-a10-pit.h +1 -0
@@ -50,6 +50,7 @@ typedef struct AwA10PITState {ptimer_state * timer[AW_A10_PIT_TIMER_NR ];AwA10TimerContext timer_context[AW_A10_PIT_TIMER_NR ];MemoryRegion iomem; +uint32_t clk_freq[4 ];uint32_t irq_enable;uint32_t irq_status;
Signature · 1 line
1.7.10.4
PATCH v5 6/7 allwinner-emac: set autonegotiation complete bit on link up
In reply to Beniamino Galvani--- hw/net/allwinner_emac.c | 4 ++-- include/hw/net/allwinner_emac.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-)
hw/net/allwinner_emac.c +2 -2
@@ -27,11 +27,11 @@ static uint8_t padding[60];static void mii_set_link (RTL8201CPState *mii,bool link_ok) {if (link_ok) { - mii->bmsr |=MII_BMSR_LINK_ST ; + mii->bmsr |=MII_BMSR_LINK_ST |MII_BMSR_AN_COMP ; mii->anlpar |=MII_ANAR_TXFD |MII_ANAR_10FD |MII_ANAR_10 |MII_ANAR_CSMACD ; }else { - mii->bmsr &= ~MII_BMSR_LINK_ST ; + mii->bmsr &= ~(MII_BMSR_LINK_ST |MII_BMSR_AN_COMP ); mii->anlpar =MII_ANAR_TX ; } }
include/hw/net/allwinner_emac.h +1 -0
@@ -144,6 +144,7 @@#define MII_BMSR_10T_FD (1 << 12)#define MII_BMSR_10T_HD (1 << 11)#define MII_BMSR_MFPS (1 << 6) +#define MII_BMSR_AN_COMP (1 << 5)#define MII_BMSR_AUTONEG (1 << 3)#define MII_BMSR_LINK_ST (1 << 2)
Signature · 1 line
1.7.10.4
PATCH v5 7/7 allwinner-emac: update irq status after writes to interrupt registers
In reply to Beniamino GalvaniThe irq line status must be updated after writes to the INT_CTL and INT_STA registers.
--- hw/net/allwinner_emac.c | 2 ++ 1 file changed, 2 insertions(+)
hw/net/allwinner_emac.c +2 -0
@@ -391,9 +391,11 @@ static void aw_emac_write(void *opaque, hwaddr offset, uint64_t value,break ;case EMAC_INT_CTL_REG : s->int_ctl = value; +aw_emac_update_irq (s);break ;case EMAC_INT_STA_REG : s->int_sta &= ~value; +aw_emac_update_irq (s);break ;case EMAC_MAC_MADR_REG : s->phy_target = value;
Signature · 1 line
1.7.10.4
Quoted 8 lines · Beniamino Galvani
This series introduces some fixes and missing features found while trying to run mainline Linux kernel on emulated Allwinner A10.
The changes concern interrupt handling, timer and ethernet MAC.
With these applied I'm able to boot Linux 3.14-rc2 using a NFS root:
Thanks; these patches have all now got review (thanks very much to Peter C for that) so I'm going to put them in the target-arm queue once development reopens post-2.0.
-- PMM