123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785 |
- /*
- * This file is subject to the terms and conditions of the GNU General Public
- * License. See the file "COPYING" in the main directory of this archive
- * for more details.
- *
- * Copyright (C) 2004-2012 Cavium, Inc.
- */
- #include <linux/interrupt.h>
- #include <linux/irqdomain.h>
- #include <linux/bitops.h>
- #include <linux/percpu.h>
- #include <linux/slab.h>
- #include <linux/irq.h>
- #include <linux/smp.h>
- #include <linux/of.h>
- #include <asm/octeon/octeon.h>
- #include <asm/octeon/cvmx-ciu2-defs.h>
- static DEFINE_PER_CPU(unsigned long, octeon_irq_ciu0_en_mirror);
- static DEFINE_PER_CPU(unsigned long, octeon_irq_ciu1_en_mirror);
- static DEFINE_PER_CPU(raw_spinlock_t, octeon_irq_ciu_spinlock);
- static __read_mostly u8 octeon_irq_ciu_to_irq[8][64];
- union octeon_ciu_chip_data {
- void *p;
- unsigned long l;
- struct {
- unsigned long line:6;
- unsigned long bit:6;
- unsigned long gpio_line:6;
- } s;
- };
- struct octeon_core_chip_data {
- struct mutex core_irq_mutex;
- bool current_en;
- bool desired_en;
- u8 bit;
- };
- #define MIPS_CORE_IRQ_LINES 8
- static struct octeon_core_chip_data octeon_irq_core_chip_data[MIPS_CORE_IRQ_LINES];
- static void octeon_irq_set_ciu_mapping(int irq, int line, int bit, int gpio_line,
- struct irq_chip *chip,
- irq_flow_handler_t handler)
- {
- union octeon_ciu_chip_data cd;
- irq_set_chip_and_handler(irq, chip, handler);
- cd.l = 0;
- cd.s.line = line;
- cd.s.bit = bit;
- cd.s.gpio_line = gpio_line;
- irq_set_chip_data(irq, cd.p);
- octeon_irq_ciu_to_irq[line][bit] = irq;
- }
- static void octeon_irq_force_ciu_mapping(struct irq_domain *domain,
- int irq, int line, int bit)
- {
- irq_domain_associate(domain, irq, line << 6 | bit);
- }
- static int octeon_coreid_for_cpu(int cpu)
- {
- #ifdef CONFIG_SMP
- return cpu_logical_map(cpu);
- #else
- return cvmx_get_core_num();
- #endif
- }
- static int octeon_cpu_for_coreid(int coreid)
- {
- #ifdef CONFIG_SMP
- return cpu_number_map(coreid);
- #else
- return smp_processor_id();
- #endif
- }
- static void octeon_irq_core_ack(struct irq_data *data)
- {
- struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
- unsigned int bit = cd->bit;
- /*
- * We don't need to disable IRQs to make these atomic since
- * they are already disabled earlier in the low level
- * interrupt code.
- */
- clear_c0_status(0x100 << bit);
- /* The two user interrupts must be cleared manually. */
- if (bit < 2)
- clear_c0_cause(0x100 << bit);
- }
- static void octeon_irq_core_eoi(struct irq_data *data)
- {
- struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
- /*
- * We don't need to disable IRQs to make these atomic since
- * they are already disabled earlier in the low level
- * interrupt code.
- */
- set_c0_status(0x100 << cd->bit);
- }
- static void octeon_irq_core_set_enable_local(void *arg)
- {
- struct irq_data *data = arg;
- struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
- unsigned int mask = 0x100 << cd->bit;
- /*
- * Interrupts are already disabled, so these are atomic.
- */
- if (cd->desired_en)
- set_c0_status(mask);
- else
- clear_c0_status(mask);
- }
- static void octeon_irq_core_disable(struct irq_data *data)
- {
- struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
- cd->desired_en = false;
- }
- static void octeon_irq_core_enable(struct irq_data *data)
- {
- struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
- cd->desired_en = true;
- }
- static void octeon_irq_core_bus_lock(struct irq_data *data)
- {
- struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
- mutex_lock(&cd->core_irq_mutex);
- }
- static void octeon_irq_core_bus_sync_unlock(struct irq_data *data)
- {
- struct octeon_core_chip_data *cd = irq_data_get_irq_chip_data(data);
- if (cd->desired_en != cd->current_en) {
- on_each_cpu(octeon_irq_core_set_enable_local, data, 1);
- cd->current_en = cd->desired_en;
- }
- mutex_unlock(&cd->core_irq_mutex);
- }
- static struct irq_chip octeon_irq_chip_core = {
- .name = "Core",
- .irq_enable = octeon_irq_core_enable,
- .irq_disable = octeon_irq_core_disable,
- .irq_ack = octeon_irq_core_ack,
- .irq_eoi = octeon_irq_core_eoi,
- .irq_bus_lock = octeon_irq_core_bus_lock,
- .irq_bus_sync_unlock = octeon_irq_core_bus_sync_unlock,
- .irq_cpu_online = octeon_irq_core_eoi,
- .irq_cpu_offline = octeon_irq_core_ack,
- .flags = IRQCHIP_ONOFFLINE_ENABLED,
- };
- static void __init octeon_irq_init_core(void)
- {
- int i;
- int irq;
- struct octeon_core_chip_data *cd;
- for (i = 0; i < MIPS_CORE_IRQ_LINES; i++) {
- cd = &octeon_irq_core_chip_data[i];
- cd->current_en = false;
- cd->desired_en = false;
- cd->bit = i;
- mutex_init(&cd->core_irq_mutex);
- irq = OCTEON_IRQ_SW0 + i;
- irq_set_chip_data(irq, cd);
- irq_set_chip_and_handler(irq, &octeon_irq_chip_core,
- handle_percpu_irq);
- }
- }
- static int next_cpu_for_irq(struct irq_data *data)
- {
- #ifdef CONFIG_SMP
- int cpu;
- int weight = cpumask_weight(data->affinity);
- if (weight > 1) {
- cpu = smp_processor_id();
- for (;;) {
- cpu = cpumask_next(cpu, data->affinity);
- if (cpu >= nr_cpu_ids) {
- cpu = -1;
- continue;
- } else if (cpumask_test_cpu(cpu, cpu_online_mask)) {
- break;
- }
- }
- } else if (weight == 1) {
- cpu = cpumask_first(data->affinity);
- } else {
- cpu = smp_processor_id();
- }
- return cpu;
- #else
- return smp_processor_id();
- #endif
- }
- static void octeon_irq_ciu_enable(struct irq_data *data)
- {
- int cpu = next_cpu_for_irq(data);
- int coreid = octeon_coreid_for_cpu(cpu);
- unsigned long *pen;
- unsigned long flags;
- union octeon_ciu_chip_data cd;
- raw_spinlock_t *lock = &per_cpu(octeon_irq_ciu_spinlock, cpu);
- cd.p = irq_data_get_irq_chip_data(data);
- raw_spin_lock_irqsave(lock, flags);
- if (cd.s.line == 0) {
- pen = &per_cpu(octeon_irq_ciu0_en_mirror, cpu);
- __set_bit(cd.s.bit, pen);
- /*
- * Must be visible to octeon_irq_ip{2,3}_ciu() before
- * enabling the irq.
- */
- wmb();
- cvmx_write_csr(CVMX_CIU_INTX_EN0(coreid * 2), *pen);
- } else {
- pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
- __set_bit(cd.s.bit, pen);
- /*
- * Must be visible to octeon_irq_ip{2,3}_ciu() before
- * enabling the irq.
- */
- wmb();
- cvmx_write_csr(CVMX_CIU_INTX_EN1(coreid * 2 + 1), *pen);
- }
- raw_spin_unlock_irqrestore(lock, flags);
- }
- static void octeon_irq_ciu_enable_local(struct irq_data *data)
- {
- unsigned long *pen;
- unsigned long flags;
- union octeon_ciu_chip_data cd;
- raw_spinlock_t *lock = &__get_cpu_var(octeon_irq_ciu_spinlock);
- cd.p = irq_data_get_irq_chip_data(data);
- raw_spin_lock_irqsave(lock, flags);
- if (cd.s.line == 0) {
- pen = &__get_cpu_var(octeon_irq_ciu0_en_mirror);
- __set_bit(cd.s.bit, pen);
- /*
- * Must be visible to octeon_irq_ip{2,3}_ciu() before
- * enabling the irq.
- */
- wmb();
- cvmx_write_csr(CVMX_CIU_INTX_EN0(cvmx_get_core_num() * 2), *pen);
- } else {
- pen = &__get_cpu_var(octeon_irq_ciu1_en_mirror);
- __set_bit(cd.s.bit, pen);
- /*
- * Must be visible to octeon_irq_ip{2,3}_ciu() before
- * enabling the irq.
- */
- wmb();
- cvmx_write_csr(CVMX_CIU_INTX_EN1(cvmx_get_core_num() * 2 + 1), *pen);
- }
- raw_spin_unlock_irqrestore(lock, flags);
- }
- static void octeon_irq_ciu_disable_local(struct irq_data *data)
- {
- unsigned long *pen;
- unsigned long flags;
- union octeon_ciu_chip_data cd;
- raw_spinlock_t *lock = &__get_cpu_var(octeon_irq_ciu_spinlock);
- cd.p = irq_data_get_irq_chip_data(data);
- raw_spin_lock_irqsave(lock, flags);
- if (cd.s.line == 0) {
- pen = &__get_cpu_var(octeon_irq_ciu0_en_mirror);
- __clear_bit(cd.s.bit, pen);
- /*
- * Must be visible to octeon_irq_ip{2,3}_ciu() before
- * enabling the irq.
- */
- wmb();
- cvmx_write_csr(CVMX_CIU_INTX_EN0(cvmx_get_core_num() * 2), *pen);
- } else {
- pen = &__get_cpu_var(octeon_irq_ciu1_en_mirror);
- __clear_bit(cd.s.bit, pen);
- /*
- * Must be visible to octeon_irq_ip{2,3}_ciu() before
- * enabling the irq.
- */
- wmb();
- cvmx_write_csr(CVMX_CIU_INTX_EN1(cvmx_get_core_num() * 2 + 1), *pen);
- }
- raw_spin_unlock_irqrestore(lock, flags);
- }
- static void octeon_irq_ciu_disable_all(struct irq_data *data)
- {
- unsigned long flags;
- unsigned long *pen;
- int cpu;
- union octeon_ciu_chip_data cd;
- raw_spinlock_t *lock;
- cd.p = irq_data_get_irq_chip_data(data);
- for_each_online_cpu(cpu) {
- int coreid = octeon_coreid_for_cpu(cpu);
- lock = &per_cpu(octeon_irq_ciu_spinlock, cpu);
- if (cd.s.line == 0)
- pen = &per_cpu(octeon_irq_ciu0_en_mirror, cpu);
- else
- pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
- raw_spin_lock_irqsave(lock, flags);
- __clear_bit(cd.s.bit, pen);
- /*
- * Must be visible to octeon_irq_ip{2,3}_ciu() before
- * enabling the irq.
- */
- wmb();
- if (cd.s.line == 0)
- cvmx_write_csr(CVMX_CIU_INTX_EN0(coreid * 2), *pen);
- else
- cvmx_write_csr(CVMX_CIU_INTX_EN1(coreid * 2 + 1), *pen);
- raw_spin_unlock_irqrestore(lock, flags);
- }
- }
- static void octeon_irq_ciu_enable_all(struct irq_data *data)
- {
- unsigned long flags;
- unsigned long *pen;
- int cpu;
- union octeon_ciu_chip_data cd;
- raw_spinlock_t *lock;
- cd.p = irq_data_get_irq_chip_data(data);
- for_each_online_cpu(cpu) {
- int coreid = octeon_coreid_for_cpu(cpu);
- lock = &per_cpu(octeon_irq_ciu_spinlock, cpu);
- if (cd.s.line == 0)
- pen = &per_cpu(octeon_irq_ciu0_en_mirror, cpu);
- else
- pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
- raw_spin_lock_irqsave(lock, flags);
- __set_bit(cd.s.bit, pen);
- /*
- * Must be visible to octeon_irq_ip{2,3}_ciu() before
- * enabling the irq.
- */
- wmb();
- if (cd.s.line == 0)
- cvmx_write_csr(CVMX_CIU_INTX_EN0(coreid * 2), *pen);
- else
- cvmx_write_csr(CVMX_CIU_INTX_EN1(coreid * 2 + 1), *pen);
- raw_spin_unlock_irqrestore(lock, flags);
- }
- }
- /*
- * Enable the irq on the next core in the affinity set for chips that
- * have the EN*_W1{S,C} registers.
- */
- static void octeon_irq_ciu_enable_v2(struct irq_data *data)
- {
- u64 mask;
- int cpu = next_cpu_for_irq(data);
- union octeon_ciu_chip_data cd;
- cd.p = irq_data_get_irq_chip_data(data);
- mask = 1ull << (cd.s.bit);
- /*
- * Called under the desc lock, so these should never get out
- * of sync.
- */
- if (cd.s.line == 0) {
- int index = octeon_coreid_for_cpu(cpu) * 2;
- set_bit(cd.s.bit, &per_cpu(octeon_irq_ciu0_en_mirror, cpu));
- cvmx_write_csr(CVMX_CIU_INTX_EN0_W1S(index), mask);
- } else {
- int index = octeon_coreid_for_cpu(cpu) * 2 + 1;
- set_bit(cd.s.bit, &per_cpu(octeon_irq_ciu1_en_mirror, cpu));
- cvmx_write_csr(CVMX_CIU_INTX_EN1_W1S(index), mask);
- }
- }
- /*
- * Enable the irq on the current CPU for chips that
- * have the EN*_W1{S,C} registers.
- */
- static void octeon_irq_ciu_enable_local_v2(struct irq_data *data)
- {
- u64 mask;
- union octeon_ciu_chip_data cd;
- cd.p = irq_data_get_irq_chip_data(data);
- mask = 1ull << (cd.s.bit);
- if (cd.s.line == 0) {
- int index = cvmx_get_core_num() * 2;
- set_bit(cd.s.bit, &__get_cpu_var(octeon_irq_ciu0_en_mirror));
- cvmx_write_csr(CVMX_CIU_INTX_EN0_W1S(index), mask);
- } else {
- int index = cvmx_get_core_num() * 2 + 1;
- set_bit(cd.s.bit, &__get_cpu_var(octeon_irq_ciu1_en_mirror));
- cvmx_write_csr(CVMX_CIU_INTX_EN1_W1S(index), mask);
- }
- }
- static void octeon_irq_ciu_disable_local_v2(struct irq_data *data)
- {
- u64 mask;
- union octeon_ciu_chip_data cd;
- cd.p = irq_data_get_irq_chip_data(data);
- mask = 1ull << (cd.s.bit);
- if (cd.s.line == 0) {
- int index = cvmx_get_core_num() * 2;
- clear_bit(cd.s.bit, &__get_cpu_var(octeon_irq_ciu0_en_mirror));
- cvmx_write_csr(CVMX_CIU_INTX_EN0_W1C(index), mask);
- } else {
- int index = cvmx_get_core_num() * 2 + 1;
- clear_bit(cd.s.bit, &__get_cpu_var(octeon_irq_ciu1_en_mirror));
- cvmx_write_csr(CVMX_CIU_INTX_EN1_W1C(index), mask);
- }
- }
- /*
- * Write to the W1C bit in CVMX_CIU_INTX_SUM0 to clear the irq.
- */
- static void octeon_irq_ciu_ack(struct irq_data *data)
- {
- u64 mask;
- union octeon_ciu_chip_data cd;
- cd.p = irq_data_get_irq_chip_data(data);
- mask = 1ull << (cd.s.bit);
- if (cd.s.line == 0) {
- int index = cvmx_get_core_num() * 2;
- cvmx_write_csr(CVMX_CIU_INTX_SUM0(index), mask);
- } else {
- cvmx_write_csr(CVMX_CIU_INT_SUM1, mask);
- }
- }
- /*
- * Disable the irq on the all cores for chips that have the EN*_W1{S,C}
- * registers.
- */
- static void octeon_irq_ciu_disable_all_v2(struct irq_data *data)
- {
- int cpu;
- u64 mask;
- union octeon_ciu_chip_data cd;
- cd.p = irq_data_get_irq_chip_data(data);
- mask = 1ull << (cd.s.bit);
- if (cd.s.line == 0) {
- for_each_online_cpu(cpu) {
- int index = octeon_coreid_for_cpu(cpu) * 2;
- clear_bit(cd.s.bit, &per_cpu(octeon_irq_ciu0_en_mirror, cpu));
- cvmx_write_csr(CVMX_CIU_INTX_EN0_W1C(index), mask);
- }
- } else {
- for_each_online_cpu(cpu) {
- int index = octeon_coreid_for_cpu(cpu) * 2 + 1;
- clear_bit(cd.s.bit, &per_cpu(octeon_irq_ciu1_en_mirror, cpu));
- cvmx_write_csr(CVMX_CIU_INTX_EN1_W1C(index), mask);
- }
- }
- }
- /*
- * Enable the irq on the all cores for chips that have the EN*_W1{S,C}
- * registers.
- */
- static void octeon_irq_ciu_enable_all_v2(struct irq_data *data)
- {
- int cpu;
- u64 mask;
- union octeon_ciu_chip_data cd;
- cd.p = irq_data_get_irq_chip_data(data);
- mask = 1ull << (cd.s.bit);
- if (cd.s.line == 0) {
- for_each_online_cpu(cpu) {
- int index = octeon_coreid_for_cpu(cpu) * 2;
- set_bit(cd.s.bit, &per_cpu(octeon_irq_ciu0_en_mirror, cpu));
- cvmx_write_csr(CVMX_CIU_INTX_EN0_W1S(index), mask);
- }
- } else {
- for_each_online_cpu(cpu) {
- int index = octeon_coreid_for_cpu(cpu) * 2 + 1;
- set_bit(cd.s.bit, &per_cpu(octeon_irq_ciu1_en_mirror, cpu));
- cvmx_write_csr(CVMX_CIU_INTX_EN1_W1S(index), mask);
- }
- }
- }
- static void octeon_irq_gpio_setup(struct irq_data *data)
- {
- union cvmx_gpio_bit_cfgx cfg;
- union octeon_ciu_chip_data cd;
- u32 t = irqd_get_trigger_type(data);
- cd.p = irq_data_get_irq_chip_data(data);
- cfg.u64 = 0;
- cfg.s.int_en = 1;
- cfg.s.int_type = (t & IRQ_TYPE_EDGE_BOTH) != 0;
- cfg.s.rx_xor = (t & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_EDGE_FALLING)) != 0;
- /* 140 nS glitch filter*/
- cfg.s.fil_cnt = 7;
- cfg.s.fil_sel = 3;
- cvmx_write_csr(CVMX_GPIO_BIT_CFGX(cd.s.gpio_line), cfg.u64);
- }
- static void octeon_irq_ciu_enable_gpio_v2(struct irq_data *data)
- {
- octeon_irq_gpio_setup(data);
- octeon_irq_ciu_enable_v2(data);
- }
- static void octeon_irq_ciu_enable_gpio(struct irq_data *data)
- {
- octeon_irq_gpio_setup(data);
- octeon_irq_ciu_enable(data);
- }
- static int octeon_irq_ciu_gpio_set_type(struct irq_data *data, unsigned int t)
- {
- irqd_set_trigger_type(data, t);
- octeon_irq_gpio_setup(data);
- return IRQ_SET_MASK_OK;
- }
- static void octeon_irq_ciu_disable_gpio_v2(struct irq_data *data)
- {
- union octeon_ciu_chip_data cd;
- cd.p = irq_data_get_irq_chip_data(data);
- cvmx_write_csr(CVMX_GPIO_BIT_CFGX(cd.s.gpio_line), 0);
- octeon_irq_ciu_disable_all_v2(data);
- }
- static void octeon_irq_ciu_disable_gpio(struct irq_data *data)
- {
- union octeon_ciu_chip_data cd;
- cd.p = irq_data_get_irq_chip_data(data);
- cvmx_write_csr(CVMX_GPIO_BIT_CFGX(cd.s.gpio_line), 0);
- octeon_irq_ciu_disable_all(data);
- }
- static void octeon_irq_ciu_gpio_ack(struct irq_data *data)
- {
- union octeon_ciu_chip_data cd;
- u64 mask;
- cd.p = irq_data_get_irq_chip_data(data);
- mask = 1ull << (cd.s.gpio_line);
- cvmx_write_csr(CVMX_GPIO_INT_CLR, mask);
- }
- static void octeon_irq_handle_gpio(unsigned int irq, struct irq_desc *desc)
- {
- if (irqd_get_trigger_type(irq_desc_get_irq_data(desc)) & IRQ_TYPE_EDGE_BOTH)
- handle_edge_irq(irq, desc);
- else
- handle_level_irq(irq, desc);
- }
- #ifdef CONFIG_SMP
- static void octeon_irq_cpu_offline_ciu(struct irq_data *data)
- {
- int cpu = smp_processor_id();
- cpumask_t new_affinity;
- if (!cpumask_test_cpu(cpu, data->affinity))
- return;
- if (cpumask_weight(data->affinity) > 1) {
- /*
- * It has multi CPU affinity, just remove this CPU
- * from the affinity set.
- */
- cpumask_copy(&new_affinity, data->affinity);
- cpumask_clear_cpu(cpu, &new_affinity);
- } else {
- /* Otherwise, put it on lowest numbered online CPU. */
- cpumask_clear(&new_affinity);
- cpumask_set_cpu(cpumask_first(cpu_online_mask), &new_affinity);
- }
- __irq_set_affinity_locked(data, &new_affinity);
- }
- static int octeon_irq_ciu_set_affinity(struct irq_data *data,
- const struct cpumask *dest, bool force)
- {
- int cpu;
- bool enable_one = !irqd_irq_disabled(data) && !irqd_irq_masked(data);
- unsigned long flags;
- union octeon_ciu_chip_data cd;
- unsigned long *pen;
- raw_spinlock_t *lock;
- cd.p = irq_data_get_irq_chip_data(data);
- /*
- * For non-v2 CIU, we will allow only single CPU affinity.
- * This removes the need to do locking in the .ack/.eoi
- * functions.
- */
- if (cpumask_weight(dest) != 1)
- return -EINVAL;
- if (!enable_one)
- return 0;
- for_each_online_cpu(cpu) {
- int coreid = octeon_coreid_for_cpu(cpu);
- lock = &per_cpu(octeon_irq_ciu_spinlock, cpu);
- raw_spin_lock_irqsave(lock, flags);
- if (cd.s.line == 0)
- pen = &per_cpu(octeon_irq_ciu0_en_mirror, cpu);
- else
- pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
- if (cpumask_test_cpu(cpu, dest) && enable_one) {
- enable_one = 0;
- __set_bit(cd.s.bit, pen);
- } else {
- __clear_bit(cd.s.bit, pen);
- }
- /*
- * Must be visible to octeon_irq_ip{2,3}_ciu() before
- * enabling the irq.
- */
- wmb();
- if (cd.s.line == 0)
- cvmx_write_csr(CVMX_CIU_INTX_EN0(coreid * 2), *pen);
- else
- cvmx_write_csr(CVMX_CIU_INTX_EN1(coreid * 2 + 1), *pen);
- raw_spin_unlock_irqrestore(lock, flags);
- }
- return 0;
- }
- /*
- * Set affinity for the irq for chips that have the EN*_W1{S,C}
- * registers.
- */
- static int octeon_irq_ciu_set_affinity_v2(struct irq_data *data,
- const struct cpumask *dest,
- bool force)
- {
- int cpu;
- bool enable_one = !irqd_irq_disabled(data) && !irqd_irq_masked(data);
- u64 mask;
- union octeon_ciu_chip_data cd;
- if (!enable_one)
- return 0;
- cd.p = irq_data_get_irq_chip_data(data);
- mask = 1ull << cd.s.bit;
- if (cd.s.line == 0) {
- for_each_online_cpu(cpu) {
- unsigned long *pen = &per_cpu(octeon_irq_ciu0_en_mirror, cpu);
- int index = octeon_coreid_for_cpu(cpu) * 2;
- if (cpumask_test_cpu(cpu, dest) && enable_one) {
- enable_one = false;
- set_bit(cd.s.bit, pen);
- cvmx_write_csr(CVMX_CIU_INTX_EN0_W1S(index), mask);
- } else {
- clear_bit(cd.s.bit, pen);
- cvmx_write_csr(CVMX_CIU_INTX_EN0_W1C(index), mask);
- }
- }
- } else {
- for_each_online_cpu(cpu) {
- unsigned long *pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
- int index = octeon_coreid_for_cpu(cpu) * 2 + 1;
- if (cpumask_test_cpu(cpu, dest) && enable_one) {
- enable_one = false;
- set_bit(cd.s.bit, pen);
- cvmx_write_csr(CVMX_CIU_INTX_EN1_W1S(index), mask);
- } else {
- clear_bit(cd.s.bit, pen);
- cvmx_write_csr(CVMX_CIU_INTX_EN1_W1C(index), mask);
- }
- }
- }
- return 0;
- }
- #endif
- /*
- * Newer octeon chips have support for lockless CIU operation.
- */
- static struct irq_chip octeon_irq_chip_ciu_v2 = {
- .name = "CIU",
- .irq_enable = octeon_irq_ciu_enable_v2,
- .irq_disable = octeon_irq_ciu_disable_all_v2,
- .irq_ack = octeon_irq_ciu_ack,
- .irq_mask = octeon_irq_ciu_disable_local_v2,
- .irq_unmask = octeon_irq_ciu_enable_v2,
- #ifdef CONFIG_SMP
- .irq_set_affinity = octeon_irq_ciu_set_affinity_v2,
- .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
- #endif
- };
- static struct irq_chip octeon_irq_chip_ciu = {
- .name = "CIU",
- .irq_enable = octeon_irq_ciu_enable,
- .irq_disable = octeon_irq_ciu_disable_all,
- .irq_ack = octeon_irq_ciu_ack,
- .irq_mask = octeon_irq_ciu_disable_local,
- .irq_unmask = octeon_irq_ciu_enable,
- #ifdef CONFIG_SMP
- .irq_set_affinity = octeon_irq_ciu_set_affinity,
- .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
- #endif
- };
- /* The mbox versions don't do any affinity or round-robin. */
- static struct irq_chip octeon_irq_chip_ciu_mbox_v2 = {
- .name = "CIU-M",
- .irq_enable = octeon_irq_ciu_enable_all_v2,
- .irq_disable = octeon_irq_ciu_disable_all_v2,
- .irq_ack = octeon_irq_ciu_disable_local_v2,
- .irq_eoi = octeon_irq_ciu_enable_local_v2,
- .irq_cpu_online = octeon_irq_ciu_enable_local_v2,
- .irq_cpu_offline = octeon_irq_ciu_disable_local_v2,
- .flags = IRQCHIP_ONOFFLINE_ENABLED,
- };
- static struct irq_chip octeon_irq_chip_ciu_mbox = {
- .name = "CIU-M",
- .irq_enable = octeon_irq_ciu_enable_all,
- .irq_disable = octeon_irq_ciu_disable_all,
- .irq_ack = octeon_irq_ciu_disable_local,
- .irq_eoi = octeon_irq_ciu_enable_local,
- .irq_cpu_online = octeon_irq_ciu_enable_local,
- .irq_cpu_offline = octeon_irq_ciu_disable_local,
- .flags = IRQCHIP_ONOFFLINE_ENABLED,
- };
- static struct irq_chip octeon_irq_chip_ciu_gpio_v2 = {
- .name = "CIU-GPIO",
- .irq_enable = octeon_irq_ciu_enable_gpio_v2,
- .irq_disable = octeon_irq_ciu_disable_gpio_v2,
- .irq_ack = octeon_irq_ciu_gpio_ack,
- .irq_mask = octeon_irq_ciu_disable_local_v2,
- .irq_unmask = octeon_irq_ciu_enable_v2,
- .irq_set_type = octeon_irq_ciu_gpio_set_type,
- #ifdef CONFIG_SMP
- .irq_set_affinity = octeon_irq_ciu_set_affinity_v2,
- #endif
- .flags = IRQCHIP_SET_TYPE_MASKED,
- };
- static struct irq_chip octeon_irq_chip_ciu_gpio = {
- .name = "CIU-GPIO",
- .irq_enable = octeon_irq_ciu_enable_gpio,
- .irq_disable = octeon_irq_ciu_disable_gpio,
- .irq_mask = octeon_irq_ciu_disable_local,
- .irq_unmask = octeon_irq_ciu_enable,
- .irq_ack = octeon_irq_ciu_gpio_ack,
- .irq_set_type = octeon_irq_ciu_gpio_set_type,
- #ifdef CONFIG_SMP
- .irq_set_affinity = octeon_irq_ciu_set_affinity,
- #endif
- .flags = IRQCHIP_SET_TYPE_MASKED,
- };
- /*
- * Watchdog interrupts are special. They are associated with a single
- * core, so we hardwire the affinity to that core.
- */
- static void octeon_irq_ciu_wd_enable(struct irq_data *data)
- {
- unsigned long flags;
- unsigned long *pen;
- int coreid = data->irq - OCTEON_IRQ_WDOG0; /* Bit 0-63 of EN1 */
- int cpu = octeon_cpu_for_coreid(coreid);
- raw_spinlock_t *lock = &per_cpu(octeon_irq_ciu_spinlock, cpu);
- raw_spin_lock_irqsave(lock, flags);
- pen = &per_cpu(octeon_irq_ciu1_en_mirror, cpu);
- __set_bit(coreid, pen);
- /*
- * Must be visible to octeon_irq_ip{2,3}_ciu() before enabling
- * the irq.
- */
- wmb();
- cvmx_write_csr(CVMX_CIU_INTX_EN1(coreid * 2 + 1), *pen);
- raw_spin_unlock_irqrestore(lock, flags);
- }
- /*
- * Watchdog interrupts are special. They are associated with a single
- * core, so we hardwire the affinity to that core.
- */
- static void octeon_irq_ciu1_wd_enable_v2(struct irq_data *data)
- {
- int coreid = data->irq - OCTEON_IRQ_WDOG0;
- int cpu = octeon_cpu_for_coreid(coreid);
- set_bit(coreid, &per_cpu(octeon_irq_ciu1_en_mirror, cpu));
- cvmx_write_csr(CVMX_CIU_INTX_EN1_W1S(coreid * 2 + 1), 1ull << coreid);
- }
- static struct irq_chip octeon_irq_chip_ciu_wd_v2 = {
- .name = "CIU-W",
- .irq_enable = octeon_irq_ciu1_wd_enable_v2,
- .irq_disable = octeon_irq_ciu_disable_all_v2,
- .irq_mask = octeon_irq_ciu_disable_local_v2,
- .irq_unmask = octeon_irq_ciu_enable_local_v2,
- };
- static struct irq_chip octeon_irq_chip_ciu_wd = {
- .name = "CIU-W",
- .irq_enable = octeon_irq_ciu_wd_enable,
- .irq_disable = octeon_irq_ciu_disable_all,
- .irq_mask = octeon_irq_ciu_disable_local,
- .irq_unmask = octeon_irq_ciu_enable_local,
- };
- static bool octeon_irq_ciu_is_edge(unsigned int line, unsigned int bit)
- {
- bool edge = false;
- if (line == 0)
- switch (bit) {
- case 48 ... 49: /* GMX DRP */
- case 50: /* IPD_DRP */
- case 52 ... 55: /* Timers */
- case 58: /* MPI */
- edge = true;
- break;
- default:
- break;
- }
- else /* line == 1 */
- switch (bit) {
- case 47: /* PTP */
- edge = true;
- break;
- default:
- break;
- }
- return edge;
- }
- struct octeon_irq_gpio_domain_data {
- unsigned int base_hwirq;
- };
- static int octeon_irq_gpio_xlat(struct irq_domain *d,
- struct device_node *node,
- const u32 *intspec,
- unsigned int intsize,
- unsigned long *out_hwirq,
- unsigned int *out_type)
- {
- unsigned int type;
- unsigned int pin;
- unsigned int trigger;
- if (d->of_node != node)
- return -EINVAL;
- if (intsize < 2)
- return -EINVAL;
- pin = intspec[0];
- if (pin >= 16)
- return -EINVAL;
- trigger = intspec[1];
- switch (trigger) {
- case 1:
- type = IRQ_TYPE_EDGE_RISING;
- break;
- case 2:
- type = IRQ_TYPE_EDGE_FALLING;
- break;
- case 4:
- type = IRQ_TYPE_LEVEL_HIGH;
- break;
- case 8:
- type = IRQ_TYPE_LEVEL_LOW;
- break;
- default:
- pr_err("Error: (%s) Invalid irq trigger specification: %x\n",
- node->name,
- trigger);
- type = IRQ_TYPE_LEVEL_LOW;
- break;
- }
- *out_type = type;
- *out_hwirq = pin;
- return 0;
- }
- static int octeon_irq_ciu_xlat(struct irq_domain *d,
- struct device_node *node,
- const u32 *intspec,
- unsigned int intsize,
- unsigned long *out_hwirq,
- unsigned int *out_type)
- {
- unsigned int ciu, bit;
- ciu = intspec[0];
- bit = intspec[1];
- if (ciu > 1 || bit > 63)
- return -EINVAL;
- /* These are the GPIO lines */
- if (ciu == 0 && bit >= 16 && bit < 32)
- return -EINVAL;
- *out_hwirq = (ciu << 6) | bit;
- *out_type = 0;
- return 0;
- }
- static struct irq_chip *octeon_irq_ciu_chip;
- static struct irq_chip *octeon_irq_gpio_chip;
- static bool octeon_irq_virq_in_range(unsigned int virq)
- {
- /* We cannot let it overflow the mapping array. */
- if (virq < (1ul << 8 * sizeof(octeon_irq_ciu_to_irq[0][0])))
- return true;
- WARN_ONCE(true, "virq out of range %u.\n", virq);
- return false;
- }
- static int octeon_irq_ciu_map(struct irq_domain *d,
- unsigned int virq, irq_hw_number_t hw)
- {
- unsigned int line = hw >> 6;
- unsigned int bit = hw & 63;
- if (!octeon_irq_virq_in_range(virq))
- return -EINVAL;
- if (line > 1 || octeon_irq_ciu_to_irq[line][bit] != 0)
- return -EINVAL;
- if (octeon_irq_ciu_is_edge(line, bit))
- octeon_irq_set_ciu_mapping(virq, line, bit, 0,
- octeon_irq_ciu_chip,
- handle_edge_irq);
- else
- octeon_irq_set_ciu_mapping(virq, line, bit, 0,
- octeon_irq_ciu_chip,
- handle_level_irq);
- return 0;
- }
- static int octeon_irq_gpio_map_common(struct irq_domain *d,
- unsigned int virq, irq_hw_number_t hw,
- int line_limit, struct irq_chip *chip)
- {
- struct octeon_irq_gpio_domain_data *gpiod = d->host_data;
- unsigned int line, bit;
- if (!octeon_irq_virq_in_range(virq))
- return -EINVAL;
- hw += gpiod->base_hwirq;
- line = hw >> 6;
- bit = hw & 63;
- if (line > line_limit || octeon_irq_ciu_to_irq[line][bit] != 0)
- return -EINVAL;
- octeon_irq_set_ciu_mapping(virq, line, bit, hw,
- chip, octeon_irq_handle_gpio);
- return 0;
- }
- static int octeon_irq_gpio_map(struct irq_domain *d,
- unsigned int virq, irq_hw_number_t hw)
- {
- return octeon_irq_gpio_map_common(d, virq, hw, 1, octeon_irq_gpio_chip);
- }
- static struct irq_domain_ops octeon_irq_domain_ciu_ops = {
- .map = octeon_irq_ciu_map,
- .xlate = octeon_irq_ciu_xlat,
- };
- static struct irq_domain_ops octeon_irq_domain_gpio_ops = {
- .map = octeon_irq_gpio_map,
- .xlate = octeon_irq_gpio_xlat,
- };
- static void octeon_irq_ip2_ciu(void)
- {
- const unsigned long core_id = cvmx_get_core_num();
- u64 ciu_sum = cvmx_read_csr(CVMX_CIU_INTX_SUM0(core_id * 2));
- ciu_sum &= __get_cpu_var(octeon_irq_ciu0_en_mirror);
- if (likely(ciu_sum)) {
- int bit = fls64(ciu_sum) - 1;
- int irq = octeon_irq_ciu_to_irq[0][bit];
- if (likely(irq))
- do_IRQ(irq);
- else
- spurious_interrupt();
- } else {
- spurious_interrupt();
- }
- }
- static void octeon_irq_ip3_ciu(void)
- {
- u64 ciu_sum = cvmx_read_csr(CVMX_CIU_INT_SUM1);
- ciu_sum &= __get_cpu_var(octeon_irq_ciu1_en_mirror);
- if (likely(ciu_sum)) {
- int bit = fls64(ciu_sum) - 1;
- int irq = octeon_irq_ciu_to_irq[1][bit];
- if (likely(irq))
- do_IRQ(irq);
- else
- spurious_interrupt();
- } else {
- spurious_interrupt();
- }
- }
- static bool octeon_irq_use_ip4;
- static void __cpuinit octeon_irq_local_enable_ip4(void *arg)
- {
- set_c0_status(STATUSF_IP4);
- }
- static void octeon_irq_ip4_mask(void)
- {
- clear_c0_status(STATUSF_IP4);
- spurious_interrupt();
- }
- static void (*octeon_irq_ip2)(void);
- static void (*octeon_irq_ip3)(void);
- static void (*octeon_irq_ip4)(void);
- void __cpuinitdata (*octeon_irq_setup_secondary)(void);
- void __cpuinit octeon_irq_set_ip4_handler(octeon_irq_ip4_handler_t h)
- {
- octeon_irq_ip4 = h;
- octeon_irq_use_ip4 = true;
- on_each_cpu(octeon_irq_local_enable_ip4, NULL, 1);
- }
- static void __cpuinit octeon_irq_percpu_enable(void)
- {
- irq_cpu_online();
- }
- static void __cpuinit octeon_irq_init_ciu_percpu(void)
- {
- int coreid = cvmx_get_core_num();
- __get_cpu_var(octeon_irq_ciu0_en_mirror) = 0;
- __get_cpu_var(octeon_irq_ciu1_en_mirror) = 0;
- wmb();
- raw_spin_lock_init(&__get_cpu_var(octeon_irq_ciu_spinlock));
- /*
- * Disable All CIU Interrupts. The ones we need will be
- * enabled later. Read the SUM register so we know the write
- * completed.
- */
- cvmx_write_csr(CVMX_CIU_INTX_EN0((coreid * 2)), 0);
- cvmx_write_csr(CVMX_CIU_INTX_EN0((coreid * 2 + 1)), 0);
- cvmx_write_csr(CVMX_CIU_INTX_EN1((coreid * 2)), 0);
- cvmx_write_csr(CVMX_CIU_INTX_EN1((coreid * 2 + 1)), 0);
- cvmx_read_csr(CVMX_CIU_INTX_SUM0((coreid * 2)));
- }
- static void octeon_irq_init_ciu2_percpu(void)
- {
- u64 regx, ipx;
- int coreid = cvmx_get_core_num();
- u64 base = CVMX_CIU2_EN_PPX_IP2_WRKQ(coreid);
- /*
- * Disable All CIU2 Interrupts. The ones we need will be
- * enabled later. Read the SUM register so we know the write
- * completed.
- *
- * There are 9 registers and 3 IPX levels with strides 0x1000
- * and 0x200 respectivly. Use loops to clear them.
- */
- for (regx = 0; regx <= 0x8000; regx += 0x1000) {
- for (ipx = 0; ipx <= 0x400; ipx += 0x200)
- cvmx_write_csr(base + regx + ipx, 0);
- }
- cvmx_read_csr(CVMX_CIU2_SUM_PPX_IP2(coreid));
- }
- static void __cpuinit octeon_irq_setup_secondary_ciu(void)
- {
- octeon_irq_init_ciu_percpu();
- octeon_irq_percpu_enable();
- /* Enable the CIU lines */
- set_c0_status(STATUSF_IP3 | STATUSF_IP2);
- clear_c0_status(STATUSF_IP4);
- }
- static void octeon_irq_setup_secondary_ciu2(void)
- {
- octeon_irq_init_ciu2_percpu();
- octeon_irq_percpu_enable();
- /* Enable the CIU lines */
- set_c0_status(STATUSF_IP3 | STATUSF_IP2);
- if (octeon_irq_use_ip4)
- set_c0_status(STATUSF_IP4);
- else
- clear_c0_status(STATUSF_IP4);
- }
- static void __init octeon_irq_init_ciu(void)
- {
- unsigned int i;
- struct irq_chip *chip;
- struct irq_chip *chip_mbox;
- struct irq_chip *chip_wd;
- struct device_node *gpio_node;
- struct device_node *ciu_node;
- struct irq_domain *ciu_domain = NULL;
- octeon_irq_init_ciu_percpu();
- octeon_irq_setup_secondary = octeon_irq_setup_secondary_ciu;
- octeon_irq_ip2 = octeon_irq_ip2_ciu;
- octeon_irq_ip3 = octeon_irq_ip3_ciu;
- if (OCTEON_IS_MODEL(OCTEON_CN58XX_PASS2_X) ||
- OCTEON_IS_MODEL(OCTEON_CN56XX_PASS2_X) ||
- OCTEON_IS_MODEL(OCTEON_CN52XX_PASS2_X) ||
- OCTEON_IS_MODEL(OCTEON_CN6XXX)) {
- chip = &octeon_irq_chip_ciu_v2;
- chip_mbox = &octeon_irq_chip_ciu_mbox_v2;
- chip_wd = &octeon_irq_chip_ciu_wd_v2;
- octeon_irq_gpio_chip = &octeon_irq_chip_ciu_gpio_v2;
- } else {
- chip = &octeon_irq_chip_ciu;
- chip_mbox = &octeon_irq_chip_ciu_mbox;
- chip_wd = &octeon_irq_chip_ciu_wd;
- octeon_irq_gpio_chip = &octeon_irq_chip_ciu_gpio;
- }
- octeon_irq_ciu_chip = chip;
- octeon_irq_ip4 = octeon_irq_ip4_mask;
- /* Mips internal */
- octeon_irq_init_core();
- gpio_node = of_find_compatible_node(NULL, NULL, "cavium,octeon-3860-gpio");
- if (gpio_node) {
- struct octeon_irq_gpio_domain_data *gpiod;
- gpiod = kzalloc(sizeof(*gpiod), GFP_KERNEL);
- if (gpiod) {
- /* gpio domain host_data is the base hwirq number. */
- gpiod->base_hwirq = 16;
- irq_domain_add_linear(gpio_node, 16, &octeon_irq_domain_gpio_ops, gpiod);
- of_node_put(gpio_node);
- } else
- pr_warn("Cannot allocate memory for GPIO irq_domain.\n");
- } else
- pr_warn("Cannot find device node for cavium,octeon-3860-gpio.\n");
- ciu_node = of_find_compatible_node(NULL, NULL, "cavium,octeon-3860-ciu");
- if (ciu_node) {
- ciu_domain = irq_domain_add_tree(ciu_node, &octeon_irq_domain_ciu_ops, NULL);
- irq_set_default_host(ciu_domain);
- of_node_put(ciu_node);
- } else
- panic("Cannot find device node for cavium,octeon-3860-ciu.");
- /* CIU_0 */
- for (i = 0; i < 16; i++)
- octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_WORKQ0, 0, i + 0);
- octeon_irq_set_ciu_mapping(OCTEON_IRQ_MBOX0, 0, 32, 0, chip_mbox, handle_percpu_irq);
- octeon_irq_set_ciu_mapping(OCTEON_IRQ_MBOX1, 0, 33, 0, chip_mbox, handle_percpu_irq);
- for (i = 0; i < 4; i++)
- octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_PCI_INT0, 0, i + 36);
- for (i = 0; i < 4; i++)
- octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_PCI_MSI0, 0, i + 40);
- octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_RML, 0, 46);
- for (i = 0; i < 4; i++)
- octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_TIMER0, 0, i + 52);
- octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_USB0, 0, 56);
- /* CIU_1 */
- for (i = 0; i < 16; i++)
- octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_WDOG0, 1, i + 0, 0, chip_wd, handle_level_irq);
- octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_USB1, 1, 17);
- /* Enable the CIU lines */
- set_c0_status(STATUSF_IP3 | STATUSF_IP2);
- clear_c0_status(STATUSF_IP4);
- }
- /*
- * Watchdog interrupts are special. They are associated with a single
- * core, so we hardwire the affinity to that core.
- */
- static void octeon_irq_ciu2_wd_enable(struct irq_data *data)
- {
- u64 mask;
- u64 en_addr;
- int coreid = data->irq - OCTEON_IRQ_WDOG0;
- union octeon_ciu_chip_data cd;
- cd.p = irq_data_get_irq_chip_data(data);
- mask = 1ull << (cd.s.bit);
- en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1S(coreid) + (0x1000ull * cd.s.line);
- cvmx_write_csr(en_addr, mask);
- }
- static void octeon_irq_ciu2_enable(struct irq_data *data)
- {
- u64 mask;
- u64 en_addr;
- int cpu = next_cpu_for_irq(data);
- int coreid = octeon_coreid_for_cpu(cpu);
- union octeon_ciu_chip_data cd;
- cd.p = irq_data_get_irq_chip_data(data);
- mask = 1ull << (cd.s.bit);
- en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1S(coreid) + (0x1000ull * cd.s.line);
- cvmx_write_csr(en_addr, mask);
- }
- static void octeon_irq_ciu2_enable_local(struct irq_data *data)
- {
- u64 mask;
- u64 en_addr;
- int coreid = cvmx_get_core_num();
- union octeon_ciu_chip_data cd;
- cd.p = irq_data_get_irq_chip_data(data);
- mask = 1ull << (cd.s.bit);
- en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1S(coreid) + (0x1000ull * cd.s.line);
- cvmx_write_csr(en_addr, mask);
- }
- static void octeon_irq_ciu2_disable_local(struct irq_data *data)
- {
- u64 mask;
- u64 en_addr;
- int coreid = cvmx_get_core_num();
- union octeon_ciu_chip_data cd;
- cd.p = irq_data_get_irq_chip_data(data);
- mask = 1ull << (cd.s.bit);
- en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1C(coreid) + (0x1000ull * cd.s.line);
- cvmx_write_csr(en_addr, mask);
- }
- static void octeon_irq_ciu2_ack(struct irq_data *data)
- {
- u64 mask;
- u64 en_addr;
- int coreid = cvmx_get_core_num();
- union octeon_ciu_chip_data cd;
- cd.p = irq_data_get_irq_chip_data(data);
- mask = 1ull << (cd.s.bit);
- en_addr = CVMX_CIU2_RAW_PPX_IP2_WRKQ(coreid) + (0x1000ull * cd.s.line);
- cvmx_write_csr(en_addr, mask);
- }
- static void octeon_irq_ciu2_disable_all(struct irq_data *data)
- {
- int cpu;
- u64 mask;
- union octeon_ciu_chip_data cd;
- cd.p = irq_data_get_irq_chip_data(data);
- mask = 1ull << (cd.s.bit);
- for_each_online_cpu(cpu) {
- u64 en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1C(octeon_coreid_for_cpu(cpu)) + (0x1000ull * cd.s.line);
- cvmx_write_csr(en_addr, mask);
- }
- }
- static void octeon_irq_ciu2_mbox_enable_all(struct irq_data *data)
- {
- int cpu;
- u64 mask;
- mask = 1ull << (data->irq - OCTEON_IRQ_MBOX0);
- for_each_online_cpu(cpu) {
- u64 en_addr = CVMX_CIU2_EN_PPX_IP3_MBOX_W1S(octeon_coreid_for_cpu(cpu));
- cvmx_write_csr(en_addr, mask);
- }
- }
- static void octeon_irq_ciu2_mbox_disable_all(struct irq_data *data)
- {
- int cpu;
- u64 mask;
- mask = 1ull << (data->irq - OCTEON_IRQ_MBOX0);
- for_each_online_cpu(cpu) {
- u64 en_addr = CVMX_CIU2_EN_PPX_IP3_MBOX_W1C(octeon_coreid_for_cpu(cpu));
- cvmx_write_csr(en_addr, mask);
- }
- }
- static void octeon_irq_ciu2_mbox_enable_local(struct irq_data *data)
- {
- u64 mask;
- u64 en_addr;
- int coreid = cvmx_get_core_num();
- mask = 1ull << (data->irq - OCTEON_IRQ_MBOX0);
- en_addr = CVMX_CIU2_EN_PPX_IP3_MBOX_W1S(coreid);
- cvmx_write_csr(en_addr, mask);
- }
- static void octeon_irq_ciu2_mbox_disable_local(struct irq_data *data)
- {
- u64 mask;
- u64 en_addr;
- int coreid = cvmx_get_core_num();
- mask = 1ull << (data->irq - OCTEON_IRQ_MBOX0);
- en_addr = CVMX_CIU2_EN_PPX_IP3_MBOX_W1C(coreid);
- cvmx_write_csr(en_addr, mask);
- }
- #ifdef CONFIG_SMP
- static int octeon_irq_ciu2_set_affinity(struct irq_data *data,
- const struct cpumask *dest, bool force)
- {
- int cpu;
- bool enable_one = !irqd_irq_disabled(data) && !irqd_irq_masked(data);
- u64 mask;
- union octeon_ciu_chip_data cd;
- if (!enable_one)
- return 0;
- cd.p = irq_data_get_irq_chip_data(data);
- mask = 1ull << cd.s.bit;
- for_each_online_cpu(cpu) {
- u64 en_addr;
- if (cpumask_test_cpu(cpu, dest) && enable_one) {
- enable_one = false;
- en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1S(octeon_coreid_for_cpu(cpu)) + (0x1000ull * cd.s.line);
- } else {
- en_addr = CVMX_CIU2_EN_PPX_IP2_WRKQ_W1C(octeon_coreid_for_cpu(cpu)) + (0x1000ull * cd.s.line);
- }
- cvmx_write_csr(en_addr, mask);
- }
- return 0;
- }
- #endif
- static void octeon_irq_ciu2_enable_gpio(struct irq_data *data)
- {
- octeon_irq_gpio_setup(data);
- octeon_irq_ciu2_enable(data);
- }
- static void octeon_irq_ciu2_disable_gpio(struct irq_data *data)
- {
- union octeon_ciu_chip_data cd;
- cd.p = irq_data_get_irq_chip_data(data);
- cvmx_write_csr(CVMX_GPIO_BIT_CFGX(cd.s.gpio_line), 0);
- octeon_irq_ciu2_disable_all(data);
- }
- static struct irq_chip octeon_irq_chip_ciu2 = {
- .name = "CIU2-E",
- .irq_enable = octeon_irq_ciu2_enable,
- .irq_disable = octeon_irq_ciu2_disable_all,
- .irq_ack = octeon_irq_ciu2_ack,
- .irq_mask = octeon_irq_ciu2_disable_local,
- .irq_unmask = octeon_irq_ciu2_enable,
- #ifdef CONFIG_SMP
- .irq_set_affinity = octeon_irq_ciu2_set_affinity,
- .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
- #endif
- };
- static struct irq_chip octeon_irq_chip_ciu2_mbox = {
- .name = "CIU2-M",
- .irq_enable = octeon_irq_ciu2_mbox_enable_all,
- .irq_disable = octeon_irq_ciu2_mbox_disable_all,
- .irq_ack = octeon_irq_ciu2_mbox_disable_local,
- .irq_eoi = octeon_irq_ciu2_mbox_enable_local,
- .irq_cpu_online = octeon_irq_ciu2_mbox_enable_local,
- .irq_cpu_offline = octeon_irq_ciu2_mbox_disable_local,
- .flags = IRQCHIP_ONOFFLINE_ENABLED,
- };
- static struct irq_chip octeon_irq_chip_ciu2_wd = {
- .name = "CIU2-W",
- .irq_enable = octeon_irq_ciu2_wd_enable,
- .irq_disable = octeon_irq_ciu2_disable_all,
- .irq_mask = octeon_irq_ciu2_disable_local,
- .irq_unmask = octeon_irq_ciu2_enable_local,
- };
- static struct irq_chip octeon_irq_chip_ciu2_gpio = {
- .name = "CIU-GPIO",
- .irq_enable = octeon_irq_ciu2_enable_gpio,
- .irq_disable = octeon_irq_ciu2_disable_gpio,
- .irq_ack = octeon_irq_ciu_gpio_ack,
- .irq_mask = octeon_irq_ciu2_disable_local,
- .irq_unmask = octeon_irq_ciu2_enable,
- .irq_set_type = octeon_irq_ciu_gpio_set_type,
- #ifdef CONFIG_SMP
- .irq_set_affinity = octeon_irq_ciu2_set_affinity,
- .irq_cpu_offline = octeon_irq_cpu_offline_ciu,
- #endif
- .flags = IRQCHIP_SET_TYPE_MASKED,
- };
- static int octeon_irq_ciu2_xlat(struct irq_domain *d,
- struct device_node *node,
- const u32 *intspec,
- unsigned int intsize,
- unsigned long *out_hwirq,
- unsigned int *out_type)
- {
- unsigned int ciu, bit;
- ciu = intspec[0];
- bit = intspec[1];
- /* Line 7 are the GPIO lines */
- if (ciu > 6 || bit > 63)
- return -EINVAL;
- *out_hwirq = (ciu << 6) | bit;
- *out_type = 0;
- return 0;
- }
- static bool octeon_irq_ciu2_is_edge(unsigned int line, unsigned int bit)
- {
- bool edge = false;
- if (line == 3) /* MIO */
- switch (bit) {
- case 2: /* IPD_DRP */
- case 8 ... 11: /* Timers */
- case 48: /* PTP */
- edge = true;
- break;
- default:
- break;
- }
- else if (line == 6) /* PKT */
- switch (bit) {
- case 52 ... 53: /* ILK_DRP */
- case 8 ... 12: /* GMX_DRP */
- edge = true;
- break;
- default:
- break;
- }
- return edge;
- }
- static int octeon_irq_ciu2_map(struct irq_domain *d,
- unsigned int virq, irq_hw_number_t hw)
- {
- unsigned int line = hw >> 6;
- unsigned int bit = hw & 63;
- if (!octeon_irq_virq_in_range(virq))
- return -EINVAL;
- /* Line 7 are the GPIO lines */
- if (line > 6 || octeon_irq_ciu_to_irq[line][bit] != 0)
- return -EINVAL;
- if (octeon_irq_ciu2_is_edge(line, bit))
- octeon_irq_set_ciu_mapping(virq, line, bit, 0,
- &octeon_irq_chip_ciu2,
- handle_edge_irq);
- else
- octeon_irq_set_ciu_mapping(virq, line, bit, 0,
- &octeon_irq_chip_ciu2,
- handle_level_irq);
- return 0;
- }
- static int octeon_irq_ciu2_gpio_map(struct irq_domain *d,
- unsigned int virq, irq_hw_number_t hw)
- {
- return octeon_irq_gpio_map_common(d, virq, hw, 7, &octeon_irq_chip_ciu2_gpio);
- }
- static struct irq_domain_ops octeon_irq_domain_ciu2_ops = {
- .map = octeon_irq_ciu2_map,
- .xlate = octeon_irq_ciu2_xlat,
- };
- static struct irq_domain_ops octeon_irq_domain_ciu2_gpio_ops = {
- .map = octeon_irq_ciu2_gpio_map,
- .xlate = octeon_irq_gpio_xlat,
- };
- static void octeon_irq_ciu2(void)
- {
- int line;
- int bit;
- int irq;
- u64 src_reg, src, sum;
- const unsigned long core_id = cvmx_get_core_num();
- sum = cvmx_read_csr(CVMX_CIU2_SUM_PPX_IP2(core_id)) & 0xfful;
- if (unlikely(!sum))
- goto spurious;
- line = fls64(sum) - 1;
- src_reg = CVMX_CIU2_SRC_PPX_IP2_WRKQ(core_id) + (0x1000 * line);
- src = cvmx_read_csr(src_reg);
- if (unlikely(!src))
- goto spurious;
- bit = fls64(src) - 1;
- irq = octeon_irq_ciu_to_irq[line][bit];
- if (unlikely(!irq))
- goto spurious;
- do_IRQ(irq);
- goto out;
- spurious:
- spurious_interrupt();
- out:
- /* CN68XX pass 1.x has an errata that accessing the ACK registers
- can stop interrupts from propagating */
- if (OCTEON_IS_MODEL(OCTEON_CN68XX))
- cvmx_read_csr(CVMX_CIU2_INTR_CIU_READY);
- else
- cvmx_read_csr(CVMX_CIU2_ACK_PPX_IP2(core_id));
- return;
- }
- static void octeon_irq_ciu2_mbox(void)
- {
- int line;
- const unsigned long core_id = cvmx_get_core_num();
- u64 sum = cvmx_read_csr(CVMX_CIU2_SUM_PPX_IP3(core_id)) >> 60;
- if (unlikely(!sum))
- goto spurious;
- line = fls64(sum) - 1;
- do_IRQ(OCTEON_IRQ_MBOX0 + line);
- goto out;
- spurious:
- spurious_interrupt();
- out:
- /* CN68XX pass 1.x has an errata that accessing the ACK registers
- can stop interrupts from propagating */
- if (OCTEON_IS_MODEL(OCTEON_CN68XX))
- cvmx_read_csr(CVMX_CIU2_INTR_CIU_READY);
- else
- cvmx_read_csr(CVMX_CIU2_ACK_PPX_IP3(core_id));
- return;
- }
- static void __init octeon_irq_init_ciu2(void)
- {
- unsigned int i;
- struct device_node *gpio_node;
- struct device_node *ciu_node;
- struct irq_domain *ciu_domain = NULL;
- octeon_irq_init_ciu2_percpu();
- octeon_irq_setup_secondary = octeon_irq_setup_secondary_ciu2;
- octeon_irq_ip2 = octeon_irq_ciu2;
- octeon_irq_ip3 = octeon_irq_ciu2_mbox;
- octeon_irq_ip4 = octeon_irq_ip4_mask;
- /* Mips internal */
- octeon_irq_init_core();
- gpio_node = of_find_compatible_node(NULL, NULL, "cavium,octeon-3860-gpio");
- if (gpio_node) {
- struct octeon_irq_gpio_domain_data *gpiod;
- gpiod = kzalloc(sizeof(*gpiod), GFP_KERNEL);
- if (gpiod) {
- /* gpio domain host_data is the base hwirq number. */
- gpiod->base_hwirq = 7 << 6;
- irq_domain_add_linear(gpio_node, 16, &octeon_irq_domain_ciu2_gpio_ops, gpiod);
- of_node_put(gpio_node);
- } else
- pr_warn("Cannot allocate memory for GPIO irq_domain.\n");
- } else
- pr_warn("Cannot find device node for cavium,octeon-3860-gpio.\n");
- ciu_node = of_find_compatible_node(NULL, NULL, "cavium,octeon-6880-ciu2");
- if (ciu_node) {
- ciu_domain = irq_domain_add_tree(ciu_node, &octeon_irq_domain_ciu2_ops, NULL);
- irq_set_default_host(ciu_domain);
- of_node_put(ciu_node);
- } else
- panic("Cannot find device node for cavium,octeon-6880-ciu2.");
- /* CUI2 */
- for (i = 0; i < 64; i++)
- octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_WORKQ0, 0, i);
- for (i = 0; i < 32; i++)
- octeon_irq_set_ciu_mapping(i + OCTEON_IRQ_WDOG0, 1, i, 0,
- &octeon_irq_chip_ciu2_wd, handle_level_irq);
- for (i = 0; i < 4; i++)
- octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_TIMER0, 3, i + 8);
- octeon_irq_force_ciu_mapping(ciu_domain, OCTEON_IRQ_USB0, 3, 44);
- for (i = 0; i < 4; i++)
- octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_PCI_INT0, 4, i);
- for (i = 0; i < 4; i++)
- octeon_irq_force_ciu_mapping(ciu_domain, i + OCTEON_IRQ_PCI_MSI0, 4, i + 8);
- irq_set_chip_and_handler(OCTEON_IRQ_MBOX0, &octeon_irq_chip_ciu2_mbox, handle_percpu_irq);
- irq_set_chip_and_handler(OCTEON_IRQ_MBOX1, &octeon_irq_chip_ciu2_mbox, handle_percpu_irq);
- irq_set_chip_and_handler(OCTEON_IRQ_MBOX2, &octeon_irq_chip_ciu2_mbox, handle_percpu_irq);
- irq_set_chip_and_handler(OCTEON_IRQ_MBOX3, &octeon_irq_chip_ciu2_mbox, handle_percpu_irq);
- /* Enable the CIU lines */
- set_c0_status(STATUSF_IP3 | STATUSF_IP2);
- clear_c0_status(STATUSF_IP4);
- }
- void __init arch_init_irq(void)
- {
- #ifdef CONFIG_SMP
- /* Set the default affinity to the boot cpu. */
- cpumask_clear(irq_default_affinity);
- cpumask_set_cpu(smp_processor_id(), irq_default_affinity);
- #endif
- if (OCTEON_IS_MODEL(OCTEON_CN68XX))
- octeon_irq_init_ciu2();
- else
- octeon_irq_init_ciu();
- }
- asmlinkage void plat_irq_dispatch(void)
- {
- unsigned long cop0_cause;
- unsigned long cop0_status;
- while (1) {
- cop0_cause = read_c0_cause();
- cop0_status = read_c0_status();
- cop0_cause &= cop0_status;
- cop0_cause &= ST0_IM;
- if (unlikely(cop0_cause & STATUSF_IP2))
- octeon_irq_ip2();
- else if (unlikely(cop0_cause & STATUSF_IP3))
- octeon_irq_ip3();
- else if (unlikely(cop0_cause & STATUSF_IP4))
- octeon_irq_ip4();
- else if (likely(cop0_cause))
- do_IRQ(fls(cop0_cause) - 9 + MIPS_CPU_IRQ_BASE);
- else
- break;
- }
- }
- #ifdef CONFIG_HOTPLUG_CPU
- void fixup_irqs(void)
- {
- irq_cpu_offline();
- }
- #endif /* CONFIG_HOTPLUG_CPU */
|