source: cmedia/trunk/Sblive/osutils.c@ 354

Last change on this file since 354 was 354, checked in by stevenhl, 17 years ago

Import untested baseline cmedia sources, work products and binaries
Binaries and work products should be deleted from repository.
once new builds are verified to work.

File size: 2.9 KB
Line 
1/* $Id: osutils.c,v 1.1 2000/04/23 14:55:45 ktk Exp $ */
2
3
4/*
5 **********************************************************************
6 * osutils.c - OS Services layer for emu10k1 driver
7 * Copyright 1999, 2000 Creative Labs, Inc.
8 *
9 **********************************************************************
10 *
11 * Date Author Summary of changes
12 * ---- ------ ------------------
13 * October 20, 1999 Bertrand Lee base code release
14 * November 2, 1999 Alan Cox cleaned up
15 *
16 **********************************************************************
17 *
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License as
20 * published by the Free Software Foundation; either version 2 of
21 * the License, or (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public
29 * License along with this program; if not, write to the Free
30 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
31 * USA.
32 *
33 **********************************************************************
34 */
35
36#include "hwaccess.h"
37
38struct memhandle *emu10k1_alloc_memphysical(u32 size)
39{
40 struct memhandle *handle;
41 u32 reqpage, order;
42
43 if ((handle = (struct memhandle *) kmalloc(sizeof(struct memhandle), GFP_KERNEL)) == NULL)
44 return handle;
45
46 DPD(3, "kmalloc: [%p]\n", handle);
47
48 order = 0;
49 reqpage = size / PAGE_SIZE;
50
51 if (size % PAGE_SIZE)
52 reqpage++;
53
54 if (reqpage != 0) {
55 reqpage--;
56 while (reqpage > 0) {
57 reqpage >>= 1;
58 order++;
59 }
60 }
61
62 if ((handle->virtaddx = (void *) __get_free_pages(GFP_KERNEL, order)) == NULL) {
63 kfree(handle);
64
65 DPD(3, "kfree: [%p]\n", handle);
66 return (void *) NULL;
67 }
68
69 /* in linux, we can directly access physical address, don't need to do
70 * phys_to_virt.
71 * In linux kernel 2.0.36, virt_to_bus does nothing, get_free_pages
72 * returns physical address. But in kernel 2.2.1 upwards,
73 * get_free_pages returns virtual address, we need to convert it
74 * to physical address. Then this physical address can be used to
75 * program hardware registers. */
76 handle->busaddx = virt_to_bus(handle->virtaddx);
77 handle->order = order;
78
79 DPD(3, "__get_free_pages: [%p] %lx\n", handle->virtaddx, handle->busaddx);
80
81 return handle;
82}
83
84void emu10k1_free_memphysical(struct memhandle *handle)
85{
86 free_pages((unsigned long) handle->virtaddx, handle->order);
87 kfree(handle);
88
89 DPD(3, "free_pages: [%p]\n", handle->virtaddx);
90 DPD(3, "kfree: [%p]\n", handle);
91
92 return;
93}
Note: See TracBrowser for help on using the repository browser.