blob: 71fc1d52a64559eaf0e60a8516cfb4ceb0a1fa91 [file] [log] [blame]
Angel Ponsc74dae92020-04-02 23:48:16 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +00002
Edward O'Callaghan91810dd2014-07-30 13:53:04 +10003#include <arch/registers.h>
4#include <console/console.h>
Stefan Reinauer38cd29e2009-08-11 21:28:25 +00005#include <device/pci.h>
Stefan Reinauer38cd29e2009-08-11 21:28:25 +00006#include <device/pci_ops.h>
Edward O'Callaghan91810dd2014-07-30 13:53:04 +10007
Patrick Georgi199b09c2012-11-22 12:46:12 +01008/* we use x86emu's register file representation */
9#include <x86emu/regs.h>
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000010
Edward O'Callaghan91810dd2014-07-30 13:53:04 +100011#include "x86.h"
12
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000013// errors go in AH. Just set these up so that word assigns
14// will work. KISS.
15enum {
Mark Marshalld08e69d2009-11-05 09:03:04 +000016 PCIBIOS_SUCCESSFUL = 0x0000,
17 PCIBIOS_UNSUPPORTED = 0x8100,
18 PCIBIOS_BADVENDOR = 0x8300,
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000019 PCIBIOS_NODEV = 0x8600,
20 PCIBIOS_BADREG = 0x8700
21};
22
Patrick Georgi199b09c2012-11-22 12:46:12 +010023int int10_handler(void)
Stefan Reinauer216fa462011-10-12 14:25:07 -070024{
Patrick Georgi503af722012-11-22 10:48:18 +010025 int res=0;
Stefan Reinauer216fa462011-10-12 14:25:07 -070026 static u8 cursor_row=0, cursor_col=0;
Patrick Georgi199b09c2012-11-22 12:46:12 +010027 switch((X86_EAX & 0xff00)>>8) {
Stefan Reinauer216fa462011-10-12 14:25:07 -070028 case 0x01: // Set cursor shape
Patrick Georgi503af722012-11-22 10:48:18 +010029 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070030 break;
31 case 0x02: // Set cursor position
Patrick Georgi199b09c2012-11-22 12:46:12 +010032 if (cursor_row != ((X86_EDX >> 8) & 0xff) ||
33 cursor_col >= (X86_EDX & 0xff)) {
Stefan Reinauer216fa462011-10-12 14:25:07 -070034 printk(BIOS_INFO, "\n");
35 }
Patrick Georgi199b09c2012-11-22 12:46:12 +010036 cursor_row = (X86_EDX >> 8) & 0xff;
37 cursor_col = X86_EDX & 0xff;
Patrick Georgi503af722012-11-22 10:48:18 +010038 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070039 break;
40 case 0x03: // Get cursor position
Patrick Georgi199b09c2012-11-22 12:46:12 +010041 X86_EAX &= 0x00ff;
42 X86_ECX = 0x0607;
43 X86_EDX = (cursor_row << 8) | cursor_col;
Patrick Georgi503af722012-11-22 10:48:18 +010044 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070045 break;
46 case 0x06: // Scroll up
47 printk(BIOS_INFO, "\n");
Patrick Georgi503af722012-11-22 10:48:18 +010048 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070049 break;
50 case 0x08: // Get Character and Mode at Cursor Position
Patrick Georgi199b09c2012-11-22 12:46:12 +010051 X86_EAX = 0x0f00 | 'A'; // White on black 'A'
Patrick Georgi503af722012-11-22 10:48:18 +010052 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070053 break;
54 case 0x09: // Write Character and attribute
Stefan Reinauer20d9de32011-12-13 23:08:03 +010055 case 0x0e: // Write Character
Patrick Georgi199b09c2012-11-22 12:46:12 +010056 printk(BIOS_INFO, "%c", X86_EAX & 0xff);
Patrick Georgi503af722012-11-22 10:48:18 +010057 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070058 break;
59 case 0x0f: // Get video mode
Patrick Georgi199b09c2012-11-22 12:46:12 +010060 X86_EAX = 0x5002; //80x25
61 X86_EBX &= 0x00ff;
Patrick Georgi503af722012-11-22 10:48:18 +010062 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070063 break;
64 default:
65 printk(BIOS_WARNING, "Unknown INT10 function %04x!\n",
Patrick Georgi199b09c2012-11-22 12:46:12 +010066 X86_EAX & 0xffff);
Stefan Reinauer216fa462011-10-12 14:25:07 -070067 break;
68 }
69 return res;
70}
Maciej Pijankaea921852009-10-27 14:29:29 +000071
Patrick Georgi199b09c2012-11-22 12:46:12 +010072int int12_handler(void)
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000073{
Patrick Georgi199b09c2012-11-22 12:46:12 +010074 X86_EAX = 64 * 1024;
Patrick Georgi503af722012-11-22 10:48:18 +010075 return 1;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +000076}
77
Patrick Georgi199b09c2012-11-22 12:46:12 +010078int int16_handler(void)
Stefan Reinauer216fa462011-10-12 14:25:07 -070079{
Patrick Georgi503af722012-11-22 10:48:18 +010080 int res=0;
Patrick Georgi199b09c2012-11-22 12:46:12 +010081 switch((X86_EAX & 0xff00)>>8) {
Stefan Reinauer216fa462011-10-12 14:25:07 -070082 case 0x00: // Check for Keystroke
Patrick Georgi199b09c2012-11-22 12:46:12 +010083 X86_EAX = 0x6120; // Space Bar, Space
Patrick Georgi503af722012-11-22 10:48:18 +010084 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070085 break;
86 case 0x01: // Check for Keystroke
Patrick Georgi199b09c2012-11-22 12:46:12 +010087 X86_EFLAGS |= 1<<6; // Zero Flag set (no key available)
Patrick Georgi503af722012-11-22 10:48:18 +010088 res = 1;
Stefan Reinauer216fa462011-10-12 14:25:07 -070089 break;
90 default:
91 printk(BIOS_WARNING, "Unknown INT16 function %04x!\n",
Patrick Georgi199b09c2012-11-22 12:46:12 +010092 X86_EAX & 0xffff);
Stefan Reinauer216fa462011-10-12 14:25:07 -070093 break;
94 }
95 return res;
96}
97
Stefan Reinauer607cdf62010-04-26 12:08:51 +000098#define PCI_CONFIG_SPACE_TYPE1 (1 << 0)
Stefan Reinauer607cdf62010-04-26 12:08:51 +000099#define PCI_SPECIAL_CYCLE_TYPE1 (1 << 4)
Stefan Reinauer607cdf62010-04-26 12:08:51 +0000100
Patrick Georgi199b09c2012-11-22 12:46:12 +0100101int int1a_handler(void)
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000102{
Patrick Georgi199b09c2012-11-22 12:46:12 +0100103 unsigned short func = (unsigned short)X86_EAX;
Patrick Georgi503af722012-11-22 10:48:18 +0100104 int retval = 1;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000105 unsigned short devid, vendorid, devfn;
Martin Roth63373ed2013-07-08 16:24:19 -0600106 /* Use short to get rid of garbage in upper half of 32-bit register */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000107 short devindex;
108 unsigned char bus;
109 struct device *dev;
Stefan Reinauer46634e72009-11-05 12:44:50 +0000110 u32 dword;
111 u16 word;
112 u8 byte, reg;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000113
Mark Marshalld08e69d2009-11-05 09:03:04 +0000114 switch (func) {
Stefan Reinauer216fa462011-10-12 14:25:07 -0700115 case 0xb101: /* PCIBIOS Check */
Patrick Georgi199b09c2012-11-22 12:46:12 +0100116 X86_EDX = 0x20494350; /* ' ICP' */
117 X86_EAX &= 0xffff0000; /* Clear AH / AL */
118 X86_EAX |= PCI_CONFIG_SPACE_TYPE1 | PCI_SPECIAL_CYCLE_TYPE1;
Stefan Reinauer607cdf62010-04-26 12:08:51 +0000119 // last bus in the system. Hard code to 255 for now.
Martin Roth63373ed2013-07-08 16:24:19 -0600120 // dev_enumerate() does not seem to tell us (publicly)
Patrick Georgi199b09c2012-11-22 12:46:12 +0100121 X86_ECX = 0xff;
122 X86_EDI = 0x00000000; /* protected mode entry */
Patrick Georgi503af722012-11-22 10:48:18 +0100123 retval = 1;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000124 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700125 case 0xb102: /* Find Device */
Patrick Georgi199b09c2012-11-22 12:46:12 +0100126 devid = X86_ECX;
127 vendorid = X86_EDX;
128 devindex = X86_ESI;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000129 dev = 0;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000130 while ((dev = dev_find_device(vendorid, devid, dev))) {
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000131 if (devindex <= 0)
132 break;
133 devindex--;
134 }
135 if (dev) {
136 unsigned short busdevfn;
Patrick Georgi199b09c2012-11-22 12:46:12 +0100137 X86_EAX &= 0xffff00ff; /* Clear AH */
138 X86_EAX |= PCIBIOS_SUCCESSFUL;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000139 // busnum is an unsigned char;
140 // devfn is an int, so we mask it off.
Arthur Heymans7fcd4d52023-08-24 15:12:19 +0200141 busdevfn = (dev->upstream->secondary << 8)
Mark Marshalld08e69d2009-11-05 09:03:04 +0000142 | (dev->path.pci.devfn & 0xff);
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000143 printk(BIOS_DEBUG, "0x%x: return 0x%x\n", func, busdevfn);
Patrick Georgi199b09c2012-11-22 12:46:12 +0100144 X86_EBX = busdevfn;
Patrick Georgi503af722012-11-22 10:48:18 +0100145 retval = 1;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000146 } else {
Patrick Georgi199b09c2012-11-22 12:46:12 +0100147 X86_EAX &= 0xffff00ff; /* Clear AH */
148 X86_EAX |= PCIBIOS_NODEV;
Patrick Georgi503af722012-11-22 10:48:18 +0100149 retval = 0;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000150 }
Mark Marshalld08e69d2009-11-05 09:03:04 +0000151 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700152 case 0xb10a: /* Read Config Dword */
153 case 0xb109: /* Read Config Word */
154 case 0xb108: /* Read Config Byte */
155 case 0xb10d: /* Write Config Dword */
156 case 0xb10c: /* Write Config Word */
157 case 0xb10b: /* Write Config Byte */
Patrick Georgi199b09c2012-11-22 12:46:12 +0100158 devfn = X86_EBX & 0xff;
159 bus = X86_EBX >> 8;
160 reg = X86_EDI;
Kyösti Mälkki98d19572019-07-04 13:15:01 +0300161 dev = pcidev_path_on_bus(bus, devfn);
Mark Marshalld08e69d2009-11-05 09:03:04 +0000162 if (!dev) {
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000163 printk(BIOS_DEBUG, "0x%x: BAD DEVICE bus %d devfn 0x%x\n", func, bus, devfn);
Stefan Reinauer607cdf62010-04-26 12:08:51 +0000164 // Or are we supposed to return PCIBIOS_NODEV?
Patrick Georgi199b09c2012-11-22 12:46:12 +0100165 X86_EAX &= 0xffff00ff; /* Clear AH */
166 X86_EAX |= PCIBIOS_BADREG;
Patrick Georgi503af722012-11-22 10:48:18 +0100167 retval = 0;
Mark Marshalld08e69d2009-11-05 09:03:04 +0000168 return retval;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000169 }
Mark Marshalld08e69d2009-11-05 09:03:04 +0000170 switch (func) {
Stefan Reinauer216fa462011-10-12 14:25:07 -0700171 case 0xb108: /* Read Config Byte */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000172 byte = pci_read_config8(dev, reg);
Patrick Georgi199b09c2012-11-22 12:46:12 +0100173 X86_ECX = byte;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000174 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700175 case 0xb109: /* Read Config Word */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000176 word = pci_read_config16(dev, reg);
Patrick Georgi199b09c2012-11-22 12:46:12 +0100177 X86_ECX = word;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000178 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700179 case 0xb10a: /* Read Config Dword */
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000180 dword = pci_read_config32(dev, reg);
Patrick Georgi199b09c2012-11-22 12:46:12 +0100181 X86_ECX = dword;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000182 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700183 case 0xb10b: /* Write Config Byte */
Patrick Georgi199b09c2012-11-22 12:46:12 +0100184 byte = X86_ECX;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000185 pci_write_config8(dev, reg, byte);
186 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700187 case 0xb10c: /* Write Config Word */
Patrick Georgi199b09c2012-11-22 12:46:12 +0100188 word = X86_ECX;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000189 pci_write_config16(dev, reg, word);
190 break;
Stefan Reinauer216fa462011-10-12 14:25:07 -0700191 case 0xb10d: /* Write Config Dword */
Patrick Georgi199b09c2012-11-22 12:46:12 +0100192 dword = X86_ECX;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000193 pci_write_config32(dev, reg, dword);
194 break;
195 }
196
Julius Wernercd49cce2019-03-05 16:53:33 -0800197#if CONFIG(REALMODE_DEBUG)
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000198 printk(BIOS_DEBUG, "0x%x: bus %d devfn 0x%x reg 0x%x val 0x%x\n",
Patrick Georgi199b09c2012-11-22 12:46:12 +0100199 func, bus, devfn, reg, X86_ECX);
Myles Watson6c9bc012010-09-07 22:30:15 +0000200#endif
Patrick Georgi199b09c2012-11-22 12:46:12 +0100201 X86_EAX &= 0xffff00ff; /* Clear AH */
202 X86_EAX |= PCIBIOS_SUCCESSFUL;
Patrick Georgi503af722012-11-22 10:48:18 +0100203 retval = 1;
Mark Marshalld08e69d2009-11-05 09:03:04 +0000204 break;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000205 default:
Mark Marshalld08e69d2009-11-05 09:03:04 +0000206 printk(BIOS_ERR, "UNSUPPORTED PCIBIOS FUNCTION 0x%x\n", func);
Patrick Georgi199b09c2012-11-22 12:46:12 +0100207 X86_EAX &= 0xffff00ff; /* Clear AH */
208 X86_EAX |= PCIBIOS_UNSUPPORTED;
Patrick Georgi503af722012-11-22 10:48:18 +0100209 retval = 0;
Stefan Reinauer38cd29e2009-08-11 21:28:25 +0000210 break;
211 }
212
213 return retval;
214}