source: trunk/hal/x86_64/drivers/pic_apic.c @ 349

Last change on this file since 349 was 349, checked in by max@…, 4 years ago

Remove unused.

File size: 3.6 KB
Line 
1/*
2 * pic_apic.c - APIC PIC driver implementation
3 *
4 * Copyright (c) 2017 Maxime Villard
5 *
6 * This file is part of ALMOS-MKH.
7 *
8 * ALMOS-MKH is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2.0 of the License.
11 *
12 * ALMOS-MKH is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <hal_types.h>
23#include <chdev.h>
24#include <pic_apic.h>
25#include <errno.h>
26#include <string.h>
27
28#include <hal_internal.h>
29#include <hal_segmentation.h>
30#include <hal_apic.h>
31
32extern iopic_input_t iopic_input;
33
34static void
35idt_set_seg(struct idt_seg *seg, void *func, int ist, int type, int dpl, int sel)
36{
37        seg->gd_looffset = (uint64_t)func & 0xffff;
38        seg->gd_selector = sel;
39        seg->gd_ist = ist;
40        seg->gd_type = type;
41        seg->gd_dpl = dpl;
42        seg->gd_p = 1;
43        seg->gd_hioffset = (uint64_t)func >> 16;
44        seg->gd_zero = 0;
45        seg->gd_xx1 = 0;
46        seg->gd_xx2 = 0;
47        seg->gd_xx3 = 0;
48}
49
50/* -------------------------------------------------------------------------- */
51
52extern uint8_t *idtstore;
53
54void pic_apic_init(chdev_t *pic)
55{
56        /* XXX APIC already initialized earlier */
57}
58
59void pic_apic_extend_init(uint32_t *xcu_base)
60{
61        x86_panic((char *)__func__);
62}
63
64void pic_apic_bind_irq(lid_t lid, chdev_t *src_chdev)
65{
66        struct idt_seg seg, *idt;
67        void *isr;
68        int slot;
69
70        /* get the source chdev functional type, channel, and direction */
71        uint32_t func    = src_chdev->func;
72        uint32_t channel = src_chdev->channel;
73
74        /* get external IRQ index */
75        uint32_t irq_id;
76        if (func == DEV_FUNC_IOC)
77                irq_id = iopic_input.ioc[channel];
78        else if (func == DEV_FUNC_TXT)
79                irq_id = iopic_input.txt[channel];
80        else
81                assert(false, __FUNCTION__, "unsupported device\n");
82
83        /* get the ISR pointer */
84        isr = src_chdev->isr;
85
86        /* create the IDT entry, and register it */
87        idt_set_seg(&seg, isr, 0, SDT_SYS386IGT, SEL_KPL,
88            GDT_FIXED_SEL(GDT_KCODE_SEL, SEL_KPL));
89        slot = idt_slot_alloc();
90        idt = (struct idt_seg *)&idtstore;
91        memcpy(&idt[slot], &seg, sizeof(struct idt_seg));
92
93        /* Bind the IRQ line in IOAPIC */
94        hal_ioapic_bind_irq(irq_id, slot, lid);
95}
96
97void pic_apic_enable_irq(lid_t lid, xptr_t src_chdev_xp)
98{
99        chdev_t *src_chdev = (chdev_t *)src_chdev_xp;
100        uint32_t func = src_chdev->func;
101        uint32_t channel = src_chdev->channel;
102        uint32_t irq_id;
103
104        /* get external IRQ index */
105        if (func == DEV_FUNC_IOC)
106                irq_id = iopic_input.ioc[channel];
107        else if (func == DEV_FUNC_TXT)
108                irq_id = iopic_input.txt[channel];
109        else
110                assert(false, __FUNCTION__, "unsupported device\n");
111
112        /* enable the line */
113        hal_ioapic_enable_irq(irq_id);
114}
115
116void pic_apic_disable_irq(lid_t lid, xptr_t src_chdev_xp)
117{
118        chdev_t *src_chdev = (chdev_t *)src_chdev_xp;
119        uint32_t func = src_chdev->func;
120        uint32_t channel = src_chdev->channel;
121        uint32_t irq_id;
122
123        /* get external IRQ index */
124        if (func == DEV_FUNC_IOC)
125                irq_id = iopic_input.ioc[channel];
126        else if (func == DEV_FUNC_TXT)
127                irq_id = iopic_input.txt[channel];
128        else
129                assert(false, __FUNCTION__, "unsupported device\n");
130
131        /* disable the line */
132        hal_ioapic_disable_irq(irq_id);
133}
134
135void pic_apic_enable_timer(uint32_t period)
136{
137        x86_panic((char *)__func__);
138}
139
140void pic_apic_enable_ipi()
141{
142        x86_panic((char *)__func__);
143}
144
145void pic_apic_send_ipi(cxy_t cxy, lid_t lid)
146{
147        x86_panic((char *)__func__);
148}
Note: See TracBrowser for help on using the repository browser.