Stefan Reinauer | 564e90f | 2012-05-04 15:37:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of i915tool |
| 3 | * |
| 4 | * Copyright (C) 2012 The ChromiumOS Authors. All rights reserved. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include "video.h" |
| 21 | |
| 22 | int find_idlist(struct drm_device *dev, u16 vendor, u16 device) |
| 23 | { |
| 24 | extern const struct pci_device_id pciidlist[]; |
| 25 | int succ = 0; |
| 26 | int i; |
| 27 | for(i = 0; pciidlist[i].vendor && !succ; i++){ |
| 28 | if (vendor == pciidlist[i].vendor && device == |
| 29 | pciidlist[i].device){ |
| 30 | dev->dev_private->info = |
| 31 | (void *)(pciidlist[i].driver_data); |
| 32 | succ = 1; |
| 33 | } |
| 34 | } |
| 35 | return succ; |
| 36 | } |
| 37 | |
| 38 | /* there's only going to be one device ... */ |
| 39 | int pci_dev_find(struct drm_device *dev) |
| 40 | { |
| 41 | struct pci_access *pacc = NULL; |
| 42 | struct pci_dev *temp; |
| 43 | int succ = 0; |
| 44 | pacc = pci_alloc(); |
| 45 | if (! pacc) |
| 46 | return 0; |
| 47 | pci_init(pacc); |
| 48 | pci_scan_bus(pacc); |
| 49 | |
| 50 | for (temp = pacc->devices; temp && ! dev->pdev; temp = temp->next){ |
| 51 | if ((temp->device_class & 0xff00) == PCI_CLASS_DISPLAY_VGA ) { |
| 52 | pci_fill_info(temp, PCI_FILL_IDENT | |
| 53 | PCI_FILL_BASES | PCI_FILL_CLASS); |
| 54 | dev->pdev = temp; |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | if (dev->pdev) |
| 59 | succ = find_idlist(dev, dev->pdev->vendor_id, |
| 60 | dev->pdev->device_id); |
| 61 | return succ; |
| 62 | } |
| 63 | |
| 64 | /* Support library for kernel style pci functions. We could do a semantic |
| 65 | * patch for it but this is easier to debug as we can fill it with prints |
| 66 | * if we want. And no cpp abuse here. Keep it simple. |
| 67 | */ |
| 68 | |
| 69 | void pci_read_config_byte(struct pci_dev *dev, unsigned long offset, u8 *val) |
| 70 | { |
| 71 | *val = pci_read_byte(dev, offset); |
| 72 | } |
| 73 | |
| 74 | void pci_write_config_byte(struct pci_dev *dev, unsigned long offset, u8 val) |
| 75 | { |
| 76 | pci_write_byte(dev, offset, val); |
| 77 | } |
| 78 | |
| 79 | void pci_read_config_word(struct pci_dev *dev, unsigned long offset, u16 *val) |
| 80 | { |
| 81 | *val = pci_read_word(dev, offset); |
| 82 | } |
| 83 | |
| 84 | void pci_write_config_word(struct pci_dev *dev, unsigned long offset, u16 val) |
| 85 | { |
| 86 | pci_write_word(dev, offset, val); |
| 87 | } |
| 88 | |
| 89 | void pci_read_config_dword(struct pci_dev *dev, unsigned long offset, u32 *val) |
| 90 | { |
| 91 | *val = pci_read_long(dev, offset); |
| 92 | } |
| 93 | |
| 94 | void pci_write_config_dword(struct pci_dev *dev, unsigned long offset, u32 val) |
| 95 | { |
| 96 | pci_write_long(dev, offset, val); |
| 97 | } |