1*39209f77Srin /* $NetBSD: openpic_common.c,v 1.9 2020/07/06 11:02:44 rin Exp $ */
280a83a2bSgarbled
380a83a2bSgarbled /*-
480a83a2bSgarbled * Copyright (c) 2007 Michael Lorenz
580a83a2bSgarbled * All rights reserved.
680a83a2bSgarbled *
780a83a2bSgarbled * Redistribution and use in source and binary forms, with or without
880a83a2bSgarbled * modification, are permitted provided that the following conditions
980a83a2bSgarbled * are met:
1080a83a2bSgarbled * 1. Redistributions of source code must retain the above copyright
1180a83a2bSgarbled * notice, this list of conditions and the following disclaimer.
1280a83a2bSgarbled * 2. Redistributions in binary form must reproduce the above copyright
1380a83a2bSgarbled * notice, this list of conditions and the following disclaimer in the
1480a83a2bSgarbled * documentation and/or other materials provided with the distribution.
1580a83a2bSgarbled *
1680a83a2bSgarbled * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
1780a83a2bSgarbled * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
1880a83a2bSgarbled * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1980a83a2bSgarbled * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2080a83a2bSgarbled * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2180a83a2bSgarbled * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2280a83a2bSgarbled * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2380a83a2bSgarbled * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2480a83a2bSgarbled * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2580a83a2bSgarbled * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2680a83a2bSgarbled * POSSIBILITY OF SUCH DAMAGE.
2780a83a2bSgarbled */
2880a83a2bSgarbled
2980a83a2bSgarbled #include <sys/cdefs.h>
30*39209f77Srin __KERNEL_RCSID(0, "$NetBSD: openpic_common.c,v 1.9 2020/07/06 11:02:44 rin Exp $");
3101fd9255Smatt
3216031f7dSrin #ifdef _KERNEL_OPT
3316031f7dSrin #include "opt_openpic.h"
3416031f7dSrin #endif
3580a83a2bSgarbled
3680a83a2bSgarbled #include <sys/param.h>
3780a83a2bSgarbled #include <sys/kernel.h>
3880a83a2bSgarbled
3980a83a2bSgarbled #include <uvm/uvm_extern.h>
4080a83a2bSgarbled
4180a83a2bSgarbled #include <machine/pio.h>
4280a83a2bSgarbled #include <powerpc/openpic.h>
4380a83a2bSgarbled
4474692028Smatt #include <powerpc/pic/picvar.h>
4580a83a2bSgarbled
4680a83a2bSgarbled volatile unsigned char *openpic_base;
4780a83a2bSgarbled
4880a83a2bSgarbled void
opic_finish_setup(struct pic_ops * pic)4980a83a2bSgarbled opic_finish_setup(struct pic_ops *pic)
5080a83a2bSgarbled {
5180a83a2bSgarbled uint32_t cpumask = 0;
5280a83a2bSgarbled int i;
5380a83a2bSgarbled
5480a83a2bSgarbled #ifdef OPENPIC_DISTRIBUTE
5580a83a2bSgarbled for (i = 0; i < ncpu; i++)
56a8260c61Schristos cpumask |= (1 << cpu_info[i].ci_index);
5780a83a2bSgarbled #else
5880a83a2bSgarbled cpumask = 1;
5980a83a2bSgarbled #endif
6080a83a2bSgarbled for (i = 0; i < pic->pic_numintrs; i++) {
6180a83a2bSgarbled /* send all interrupts to all active CPUs */
6280a83a2bSgarbled openpic_write(OPENPIC_IDEST(i), cpumask);
6380a83a2bSgarbled }
6480a83a2bSgarbled }
6580a83a2bSgarbled
6680a83a2bSgarbled void
openpic_set_priority(int cpu,int pri)6780a83a2bSgarbled openpic_set_priority(int cpu, int pri)
6880a83a2bSgarbled {
6980a83a2bSgarbled u_int x;
7080a83a2bSgarbled
7180a83a2bSgarbled x = openpic_read(OPENPIC_CPU_PRIORITY(cpu));
7280a83a2bSgarbled x &= ~OPENPIC_CPU_PRIORITY_MASK;
7380a83a2bSgarbled x |= pri;
7480a83a2bSgarbled openpic_write(OPENPIC_CPU_PRIORITY(cpu), x);
7580a83a2bSgarbled }
7680a83a2bSgarbled
7780a83a2bSgarbled int
opic_get_irq(struct pic_ops * pic,int mode)7880a83a2bSgarbled opic_get_irq(struct pic_ops *pic, int mode)
7980a83a2bSgarbled {
8080a83a2bSgarbled
8197922837Sgarbled return openpic_read_irq(curcpu()->ci_index);
8280a83a2bSgarbled }
8380a83a2bSgarbled
8480a83a2bSgarbled void
opic_ack_irq(struct pic_ops * pic,int irq)8580a83a2bSgarbled opic_ack_irq(struct pic_ops *pic, int irq)
8680a83a2bSgarbled {
8780a83a2bSgarbled
8897922837Sgarbled openpic_eoi(curcpu()->ci_index);
8980a83a2bSgarbled }
90