13 #include <linux/module.h>
14 #include <linux/pci.h>
18 #include <linux/slab.h>
24 #define HP_ZX1_IOC_OFFSET 0x1000
27 #define HP_ZX1_IBASE 0x300
28 #define HP_ZX1_IMASK 0x308
29 #define HP_ZX1_PCOM 0x310
30 #define HP_ZX1_TCNFG 0x318
31 #define HP_ZX1_PDIR_BASE 0x320
33 #define HP_ZX1_IOVA_BASE GB(1UL)
34 #define HP_ZX1_IOVA_SIZE GB(1UL)
35 #define HP_ZX1_GART_SIZE (HP_ZX1_IOVA_SIZE / 2)
36 #define HP_ZX1_SBA_IOMMU_COOKIE 0x0000badbadc0ffeeUL
38 #define HP_ZX1_PDIR_VALID_BIT 0x8000000000000000UL
39 #define HP_ZX1_IOVA_TO_PDIR(va) ((va - hp_private.iova_base) >> hp_private.io_tlb_shift)
41 #define AGP8X_MODE_BIT 3
42 #define AGP8X_MODE (1 << AGP8X_MODE_BIT)
45 static struct pci_dev fake_bridge_dev;
47 static int hp_zx1_gart_found;
59 static struct _hp_private {
74 int io_pages_per_kpage;
77 static int __init hp_zx1_ioc_shared(
void)
79 struct _hp_private *hp = &hp_private;
90 switch (hp->io_tlb_ps) {
91 case 0: hp->io_tlb_shift = 12;
break;
92 case 1: hp->io_tlb_shift = 13;
break;
93 case 2: hp->io_tlb_shift = 14;
break;
94 case 3: hp->io_tlb_shift = 16;
break;
97 "configuration 0x%x\n", hp->io_tlb_ps);
102 hp->io_page_size = 1 << hp->io_tlb_shift;
103 hp->io_pages_per_kpage =
PAGE_SIZE / hp->io_page_size;
109 hp->gatt_entries = hp->gart_size / hp->io_page_size;
117 hp->gatt_entries = 0;
127 hp_zx1_ioc_owner (
void)
129 struct _hp_private *hp = &hp_private;
137 hp->io_tlb_shift = 16;
140 hp->io_tlb_shift = 14;
143 hp->io_tlb_shift = 13;
146 hp->io_tlb_shift = 12;
149 hp->io_page_size = 1 << hp->io_tlb_shift;
150 hp->io_pages_per_kpage =
PAGE_SIZE / hp->io_page_size;
156 hp->gatt_entries = hp->gart_size / hp->io_page_size;
165 struct _hp_private *hp = &hp_private;
167 hp->ioc_regs =
ioremap(hpa, 1024);
177 if (hp->io_pdir_owner)
178 return hp_zx1_ioc_owner();
180 return hp_zx1_ioc_shared();
184 hp_zx1_lba_find_capability (
volatile u8 __iomem *hpa,
int cap)
194 while (ttl-- && pos >= 0x40) {
207 hp_zx1_lba_init (
u64 hpa)
209 struct _hp_private *hp = &hp_private;
212 hp->lba_regs =
ioremap(hpa, 256);
216 hp->lba_cap_offset = hp_zx1_lba_find_capability(hp->lba_regs,
PCI_CAP_ID_AGP);
218 cap =
readl(hp->lba_regs+hp->lba_cap_offset) & 0xff;
221 cap, hp->lba_cap_offset);
230 hp_zx1_fetch_size(
void)
234 size = hp_private.gart_size /
MB(1);
236 agp_bridge->current_size = (
void *) &hp_zx1_sizes[0];
241 hp_zx1_configure (
void)
243 struct _hp_private *hp = &hp_private;
249 if (hp->io_pdir_owner) {
266 hp_zx1_cleanup (
void)
268 struct _hp_private *hp = &hp_private;
271 if (hp->io_pdir_owner) {
284 struct _hp_private *hp = &hp_private;
293 struct _hp_private *hp = &hp_private;
296 if (hp->io_pdir_owner) {
301 "memory for I/O PDIR\n");
303 hp->gatt_entries = 0;
306 memset(hp->io_pdir, 0, hp->io_pdir_size);
311 for (i = 0; i < hp->gatt_entries; i++) {
321 struct _hp_private *hp = &hp_private;
323 if (hp->io_pdir_owner)
334 struct _hp_private *hp = &hp_private;
339 if (type != mem->
type ||
344 io_pg_start = hp->io_pages_per_kpage * pg_start;
345 io_pg_count = hp->io_pages_per_kpage * mem->
page_count;
346 if ((io_pg_start + io_pg_count) > hp->gatt_entries) {
351 while (j < (io_pg_start + io_pg_count)) {
363 for (i = 0, j = io_pg_start; i < mem->
page_count; i++) {
368 k < hp->io_pages_per_kpage;
369 k++, j++, paddr += hp->io_page_size) {
379 hp_zx1_remove_memory (
struct agp_memory *mem,
off_t pg_start,
int type)
381 struct _hp_private *hp = &hp_private;
382 int i, io_pg_start, io_pg_count;
384 if (type != mem->
type ||
389 io_pg_start = hp->io_pages_per_kpage * pg_start;
390 io_pg_count = hp->io_pages_per_kpage * mem->
page_count;
391 for (i = io_pg_start; i < io_pg_count + io_pg_start; i++) {
408 struct _hp_private *hp = &hp_private;
413 command |= 0x00000100;
423 .configure = hp_zx1_configure,
424 .fetch_size = hp_zx1_fetch_size,
425 .cleanup = hp_zx1_cleanup,
426 .tlb_flush = hp_zx1_tlbflush,
427 .mask_memory = hp_zx1_mask_memory,
428 .masks = hp_zx1_masks,
429 .agp_enable = hp_zx1_enable,
431 .create_gatt_table = hp_zx1_create_gatt_table,
432 .free_gatt_table = hp_zx1_free_gatt_table,
433 .insert_memory = hp_zx1_insert_memory,
434 .remove_memory = hp_zx1_remove_memory,
442 .cant_use_aperture =
true,
446 hp_zx1_setup (
u64 ioc_hpa,
u64 lba_hpa)
451 error = hp_zx1_ioc_init(ioc_hpa);
455 error = hp_zx1_lba_init(lba_hpa);
468 bridge->
dev = &fake_bridge_dev;
504 "AGP LBA but no IOC.\n");
521 "(ioc=%llx, lba=%llx)\n", (
char *)context,
524 hp_zx1_gart_found = 1;
535 if (hp_zx1_gart_found)
539 if (hp_zx1_gart_found)
546 agp_hp_cleanup (
void)